mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
chore: return statement optimization (#406)
This commit is contained in:
parent
a3c392cdde
commit
743fc8500b
5 changed files with 29 additions and 60 deletions
|
|
@ -588,17 +588,16 @@ func (XDCX *XDCX) GetEmptyTradingState() (*tradingstate.TradingStateDB, error) {
|
||||||
func (XDCx *XDCX) GetStateCache() tradingstate.Database {
|
func (XDCx *XDCX) GetStateCache() tradingstate.Database {
|
||||||
return XDCx.StateCache
|
return XDCx.StateCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (XDCx *XDCX) HasTradingState(block *types.Block, author common.Address) bool {
|
func (XDCx *XDCX) HasTradingState(block *types.Block, author common.Address) bool {
|
||||||
root, err := XDCx.GetTradingStateRoot(block, author)
|
root, err := XDCx.GetTradingStateRoot(block, author)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
_, err = XDCx.StateCache.OpenTrie(root)
|
_, err = XDCx.StateCache.OpenTrie(root)
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (XDCx *XDCX) GetTriegc() *prque.Prque {
|
func (XDCx *XDCX) GetTriegc() *prque.Prque {
|
||||||
return XDCx.Triegc
|
return XDCx.Triegc
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,7 @@ func IsResignedRelayer(relayer common.Address, statedb *state.StateDB) bool {
|
||||||
slot := RelayerMappingSlot["RESIGN_REQUESTS"]
|
slot := RelayerMappingSlot["RESIGN_REQUESTS"]
|
||||||
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
|
locBig := GetLocMappingAtKey(relayer.Hash(), slot)
|
||||||
locHash := common.BigToHash(locBig)
|
locHash := common.BigToHash(locBig)
|
||||||
if statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash) != (common.Hash{}) {
|
return statedb.GetState(common.HexToAddress(common.RelayerRegistrationSMC), locHash) != (common.Hash{})
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
|
func GetBaseTokenLength(relayer common.Address, statedb *state.StateDB) uint64 {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import (
|
||||||
var (
|
var (
|
||||||
// ErrInvalidLengdingSig invalidate signer
|
// ErrInvalidLengdingSig invalidate signer
|
||||||
ErrInvalidLengdingSig = errors.New("invalid transaction v, r, s values")
|
ErrInvalidLengdingSig = errors.New("invalid transaction v, r, s values")
|
||||||
errNoSignerLengding = errors.New("missing signing methods")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -86,50 +85,32 @@ type lendingtxdata struct {
|
||||||
|
|
||||||
// IsCreatedLending check if tx is cancelled transaction
|
// IsCreatedLending check if tx is cancelled transaction
|
||||||
func (tx *LendingTransaction) IsCreatedLending() bool {
|
func (tx *LendingTransaction) IsCreatedLending() bool {
|
||||||
if (tx.IsLoTypeLending() || tx.IsMoTypeLending()) && tx.Status() == LendingStatusNew {
|
return (tx.IsLoTypeLending() || tx.IsMoTypeLending()) && tx.Status() == LendingStatusNew
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsCancelledLending check if tx is cancelled transaction
|
// IsCancelledLending check if tx is cancelled transaction
|
||||||
func (tx *LendingTransaction) IsCancelledLending() bool {
|
func (tx *LendingTransaction) IsCancelledLending() bool {
|
||||||
if tx.Status() == LendingStatusCancelled {
|
return tx.Status() == LendingStatusCancelled
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsRepayLending check if tx is repay lending transaction
|
// IsRepayLending check if tx is repay lending transaction
|
||||||
func (tx *LendingTransaction) IsRepayLending() bool {
|
func (tx *LendingTransaction) IsRepayLending() bool {
|
||||||
if tx.Type() == LendingRePay {
|
return tx.Type() == LendingRePay
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTopupLending check if tx is repay lending transaction
|
// IsTopupLending check if tx is repay lending transaction
|
||||||
func (tx *LendingTransaction) IsTopupLending() bool {
|
func (tx *LendingTransaction) IsTopupLending() bool {
|
||||||
if tx.Type() == LendingTopup {
|
return tx.Type() == LendingTopup
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsMoTypeLending check if tx type is MO lending
|
// IsMoTypeLending check if tx type is MO lending
|
||||||
func (tx *LendingTransaction) IsMoTypeLending() bool {
|
func (tx *LendingTransaction) IsMoTypeLending() bool {
|
||||||
if tx.Type() == LendingTypeMo {
|
return tx.Type() == LendingTypeMo
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLoTypeLending check if tx type is LO lending
|
// IsLoTypeLending check if tx type is LO lending
|
||||||
func (tx *LendingTransaction) IsLoTypeLending() bool {
|
func (tx *LendingTransaction) IsLoTypeLending() bool {
|
||||||
if tx.Type() == LendingTypeLo {
|
return tx.Type() == LendingTypeLo
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder
|
// EncodeRLP implements rlp.Encoder
|
||||||
|
|
@ -363,7 +344,7 @@ func (s *LendingTxByNonce) Pop() interface{} {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
//LendingTransactionByNonce sort transaction by nonce
|
// LendingTransactionByNonce sort transaction by nonce
|
||||||
type LendingTransactionByNonce struct {
|
type LendingTransactionByNonce struct {
|
||||||
txs map[common.Address]LendingTransactions
|
txs map[common.Address]LendingTransactions
|
||||||
heads LendingTxByNonce
|
heads LendingTxByNonce
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import (
|
||||||
var (
|
var (
|
||||||
// ErrInvalidOrderSig invalidate signer
|
// ErrInvalidOrderSig invalidate signer
|
||||||
ErrInvalidOrderSig = errors.New("invalid transaction v, r, s values")
|
ErrInvalidOrderSig = errors.New("invalid transaction v, r, s values")
|
||||||
errNoSignerOrder = errors.New("missing signing methods")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -77,26 +76,17 @@ type ordertxdata struct {
|
||||||
|
|
||||||
// IsCancelledOrder check if tx is cancelled transaction
|
// IsCancelledOrder check if tx is cancelled transaction
|
||||||
func (tx *OrderTransaction) IsCancelledOrder() bool {
|
func (tx *OrderTransaction) IsCancelledOrder() bool {
|
||||||
if tx.Status() == OrderStatusCancelled {
|
return tx.Status() == OrderStatusCancelled
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsMoTypeOrder check if tx type is MO Order
|
// IsMoTypeOrder check if tx type is MO Order
|
||||||
func (tx *OrderTransaction) IsMoTypeOrder() bool {
|
func (tx *OrderTransaction) IsMoTypeOrder() bool {
|
||||||
if tx.Type() == OrderTypeMo {
|
return tx.Type() == OrderTypeMo
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLoTypeOrder check if tx type is LO Order
|
// IsLoTypeOrder check if tx type is LO Order
|
||||||
func (tx *OrderTransaction) IsLoTypeOrder() bool {
|
func (tx *OrderTransaction) IsLoTypeOrder() bool {
|
||||||
if tx.Type() == OrderTypeLo {
|
return tx.Type() == OrderTypeLo
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder
|
// EncodeRLP implements rlp.Encoder
|
||||||
|
|
@ -166,7 +156,6 @@ func (tx *OrderTransaction) WithSignature(signer OrderSigner, sig []byte) (*Orde
|
||||||
|
|
||||||
// ImportSignature make order tx with specific signature
|
// ImportSignature make order tx with specific signature
|
||||||
func (tx *OrderTransaction) ImportSignature(V, R, S *big.Int) *OrderTransaction {
|
func (tx *OrderTransaction) ImportSignature(V, R, S *big.Int) *OrderTransaction {
|
||||||
|
|
||||||
if V != nil {
|
if V != nil {
|
||||||
tx.data.V = V
|
tx.data.V = V
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -274,7 +274,9 @@ func GenerateNewParams(G, H []ECPoint, x *big.Int, L, R, P ECPoint) ([]ECPoint,
|
||||||
return Gprime, Hprime, Pprime
|
return Gprime, Hprime, Pprime
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inner Product Argument
|
/*
|
||||||
|
Inner Product Argument
|
||||||
|
|
||||||
Proves that <a,b>=c
|
Proves that <a,b>=c
|
||||||
This is a building block for BulletProofs
|
This is a building block for BulletProofs
|
||||||
*/
|
*/
|
||||||
|
|
@ -323,7 +325,7 @@ func InnerProductProveSub(proof InnerProdArg, G, H []ECPoint, a []*big.Int, b []
|
||||||
return InnerProductProveSub(proof, Gprime, Hprime, aprime, bprime, u, Pprime)
|
return InnerProductProveSub(proof, Gprime, Hprime, aprime, bprime, u, Pprime)
|
||||||
}
|
}
|
||||||
|
|
||||||
//rpresult.IPP = InnerProductProve(left, right, that, P, EC.U, EC.BPG, HPrime)
|
// rpresult.IPP = InnerProductProve(left, right, that, P, EC.U, EC.BPG, HPrime)
|
||||||
func InnerProductProve(a []*big.Int, b []*big.Int, c *big.Int, P, U ECPoint, G, H []ECPoint) InnerProdArg {
|
func InnerProductProve(a []*big.Int, b []*big.Int, c *big.Int, P, U ECPoint, G, H []ECPoint) InnerProdArg {
|
||||||
loglen := int(math.Log2(float64(len(a))))
|
loglen := int(math.Log2(float64(len(a))))
|
||||||
|
|
||||||
|
|
@ -353,7 +355,9 @@ func InnerProductProve(a []*big.Int, b []*big.Int, c *big.Int, P, U ECPoint, G,
|
||||||
return InnerProductProveSub(runningProof, G, H, a, b, ux, Pprime)
|
return InnerProductProveSub(runningProof, G, H, a, b, ux, Pprime)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inner Product Verify
|
/*
|
||||||
|
Inner Product Verify
|
||||||
|
|
||||||
Given a inner product proof, verifies the correctness of the proof
|
Given a inner product proof, verifies the correctness of the proof
|
||||||
Since we're using the Fiat-Shamir transform, we need to verify all x hash computations,
|
Since we're using the Fiat-Shamir transform, we need to verify all x hash computations,
|
||||||
all g' and h' computations
|
all g' and h' computations
|
||||||
|
|
@ -416,11 +420,7 @@ func InnerProductVerify(c *big.Int, P, U ECPoint, G, H []ECPoint, ipp InnerProdA
|
||||||
Pcalc3 := ux.Mult(ccalc)
|
Pcalc3 := ux.Mult(ccalc)
|
||||||
Pcalc := Pcalc1.Add(Pcalc2).Add(Pcalc3)
|
Pcalc := Pcalc1.Add(Pcalc2).Add(Pcalc3)
|
||||||
|
|
||||||
if !Pprime.Equal(Pcalc) {
|
return Pprime.Equal(Pcalc)
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Inner Product Verify Fast
|
/* Inner Product Verify Fast
|
||||||
|
|
@ -961,11 +961,14 @@ MultiRangeProof Prove
|
||||||
Takes in a list of values and provides an aggregate
|
Takes in a list of values and provides an aggregate
|
||||||
range proof for all the values.
|
range proof for all the values.
|
||||||
changes:
|
changes:
|
||||||
all values are concatenated
|
|
||||||
r(x) is computed differently
|
all values are concatenated
|
||||||
tau_x calculation is different
|
r(x) is computed differently
|
||||||
delta calculation is different
|
tau_x calculation is different
|
||||||
|
delta calculation is different
|
||||||
|
|
||||||
{(g, h \in G, \textbf{V} \in G^m ; \textbf{v, \gamma} \in Z_p^m) :
|
{(g, h \in G, \textbf{V} \in G^m ; \textbf{v, \gamma} \in Z_p^m) :
|
||||||
|
|
||||||
V_j = h^{\gamma_j}g^{v_j} \wedge v_j \in [0, 2^n - 1] \forall j \in [1, m]}
|
V_j = h^{\gamma_j}g^{v_j} \wedge v_j \in [0, 2^n - 1] \forall j \in [1, m]}
|
||||||
*/
|
*/
|
||||||
var bitsPerValue = 64
|
var bitsPerValue = 64
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue