Skip to content

Commit

Permalink
comment fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dusannosovic-ethernal committed Feb 13, 2024
1 parent 81e3aff commit fec4957
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 83 deletions.
1 change: 1 addition & 0 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ func (p *TxPool) validateTx(tx *types.Transaction) error {
}

if tx.GetGasPrice(baseFee).Cmp(new(big.Int).SetUint64(p.priceLimit)) < 0 {
// Make sure that the transaction is not underpriced
metrics.IncrCounter([]string{txPoolMetrics, "underpriced_tx"}, 1)

return ErrUnderpriced
Expand Down
34 changes: 14 additions & 20 deletions types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,33 +204,27 @@ func (tx *AccessListTxn) setHash(h Hash) {
// Use UnmarshalRLP in most cases
func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error {
numOfElems := 11
var values rlpValues

elems, err := v.GetElems()
values, err := v.GetElems()
if err != nil {
return err
}

getElem := func() *fastrlp.Value {
val := elems[0]
elems = elems[1:]

return val
}

if numElems := len(elems); numElems != numOfElems {
if numElems := len(values); numElems != numOfElems {
return fmt.Errorf("incorrect number of transaction elements, expected %d but found %d", numOfElems, numElems)
}

txChainID := new(big.Int)

if err = getElem().GetBigInt(txChainID); err != nil {
if err = values.dequeueValue().GetBigInt(txChainID); err != nil {
return err
}

tx.setChainID(txChainID)

// nonce
txNonce, err := getElem().GetUint64()
txNonce, err := values.dequeueValue().GetUint64()
if err != nil {
return err
}
Expand All @@ -239,22 +233,22 @@ func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) e

// gasPrice
txGasPrice := new(big.Int)
if err = getElem().GetBigInt(txGasPrice); err != nil {
if err = values.dequeueValue().GetBigInt(txGasPrice); err != nil {
return err
}

tx.setGasPrice(txGasPrice)

// gas
txGas, err := getElem().GetUint64()
txGas, err := values.dequeueValue().GetUint64()
if err != nil {
return err
}

tx.setGas(txGas)

// to
if vv, _ := getElem().Bytes(); len(vv) == 20 {
if vv, _ := values.dequeueValue().Bytes(); len(vv) == 20 {
// address
addr := BytesToAddress(vv)
tx.setTo(&addr)
Expand All @@ -265,7 +259,7 @@ func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) e

// value
txValue := new(big.Int)
if err = getElem().GetBigInt(txValue); err != nil {
if err = values.dequeueValue().GetBigInt(txValue); err != nil {
return err
}

Expand All @@ -274,15 +268,15 @@ func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) e
// input
var txInput []byte

txInput, err = getElem().GetBytes(txInput)
txInput, err = values.dequeueValue().GetBytes(txInput)
if err != nil {
return err
}

tx.setInput(txInput)

//accessList
accessListVV, err := getElem().GetElems()
accessListVV, err := values.dequeueValue().GetElems()
if err != nil {
return err
}
Expand All @@ -300,19 +294,19 @@ func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) e

// V
txV := new(big.Int)
if err = getElem().GetBigInt(txV); err != nil {
if err = values.dequeueValue().GetBigInt(txV); err != nil {
return err
}

// R
txR := new(big.Int)
if err = getElem().GetBigInt(txR); err != nil {
if err = values.dequeueValue().GetBigInt(txR); err != nil {
return err
}

// S
txS := new(big.Int)
if err = getElem().GetBigInt(txS); err != nil {
if err = values.dequeueValue().GetBigInt(txS); err != nil {
return err
}

Expand Down
37 changes: 15 additions & 22 deletions types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,27 @@ func (tx *DynamicFeeTx) setHash(h Hash) { tx.Hash = h }
// Use UnmarshalRLP in most cases
func (tx *DynamicFeeTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error {
numOfElems := 12
var values rlpValues

elems, err := v.GetElems()
values, err := v.GetElems()
if err != nil {
return err
}

getElem := func() *fastrlp.Value {
val := elems[0]
elems = elems[1:]

return val
}

if numElems := len(elems); numElems != numOfElems {
if numElems := len(values); numElems != numOfElems {
return fmt.Errorf("incorrect number of transaction elements, expected %d but found %d", numOfElems, numElems)
}

// Load Chain ID
txChainID := new(big.Int)
if err = getElem().GetBigInt(txChainID); err != nil {
if err = values.dequeueValue().GetBigInt(txChainID); err != nil {
return err
}

tx.setChainID(txChainID)

// nonce
txNonce, err := getElem().GetUint64()
txNonce, err := values.dequeueValue().GetUint64()
if err != nil {
return err
}
Expand All @@ -132,31 +126,30 @@ func (tx *DynamicFeeTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) er

// gasTipCap
txGasTipCap := new(big.Int)
if err = getElem().GetBigInt(txGasTipCap); err != nil {
if err = values.dequeueValue().GetBigInt(txGasTipCap); err != nil {
return err
}

tx.setGasTipCap(txGasTipCap)

// gasFeeCap
txGasFeeCap := new(big.Int)
if err = getElem().GetBigInt(txGasFeeCap); err != nil {
if err = values.dequeueValue().GetBigInt(txGasFeeCap); err != nil {
return err
}

tx.setGasFeeCap(txGasFeeCap)

// gas
txGas, err := getElem().GetUint64()
txGas, err := values.dequeueValue().GetUint64()
if err != nil {
return err
}

tx.setGas(txGas)

// to
if vv, _ := getElem().Bytes(); len(vv) == 20 {
// address
if vv, _ := values.dequeueValue().Bytes(); len(vv) == 20 {
addr := BytesToAddress(vv)
tx.setTo(&addr)
} else {
Expand All @@ -166,7 +159,7 @@ func (tx *DynamicFeeTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) er

// value
txValue := new(big.Int)
if err = getElem().GetBigInt(txValue); err != nil {
if err = values.dequeueValue().GetBigInt(txValue); err != nil {
return err
}

Expand All @@ -175,14 +168,14 @@ func (tx *DynamicFeeTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) er
// input
var txInput []byte

txInput, err = getElem().GetBytes(txInput)
txInput, err = values.dequeueValue().GetBytes(txInput)
if err != nil {
return err
}

tx.setInput(txInput)

accessListVV, err := getElem().GetElems()
accessListVV, err := values.dequeueValue().GetElems()
if err != nil {
return err
}
Expand All @@ -200,19 +193,19 @@ func (tx *DynamicFeeTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) er

// V
txV := new(big.Int)
if err = getElem().GetBigInt(txV); err != nil {
if err = values.dequeueValue().GetBigInt(txV); err != nil {
return err
}

// R
txR := new(big.Int)
if err = getElem().GetBigInt(txR); err != nil {
if err = values.dequeueValue().GetBigInt(txR); err != nil {
return err
}

// S
txS := new(big.Int)
if err = getElem().GetBigInt(txS); err != nil {
if err = values.dequeueValue().GetBigInt(txS); err != nil {
return err
}

Expand Down
30 changes: 12 additions & 18 deletions types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,19 @@ func (tx *LegacyTx) setHash(h Hash) { tx.Hash = h }
// Use UnmarshalRLP in most cases
func (tx *LegacyTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error {
num := 9
var values rlpValues

elems, err := v.GetElems()
values, err := v.GetElems()
if err != nil {
return err
}

getElem := func() *fastrlp.Value {
val := elems[0]
elems = elems[1:]

return val
}

if numElems := len(elems); numElems != num {
if numElems := len(values); numElems != num {
return fmt.Errorf("legacy incorrect number of transaction elements, expected %d but found %d", num, numElems)
}

// nonce
txNonce, err := getElem().GetUint64()
txNonce, err := values.dequeueValue().GetUint64()
if err != nil {
return err
}
Expand All @@ -118,22 +112,22 @@ func (tx *LegacyTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

// gasPrice
txGasPrice := new(big.Int)
if err = getElem().GetBigInt(txGasPrice); err != nil {
if err = values.dequeueValue().GetBigInt(txGasPrice); err != nil {
return err
}

tx.setGasPrice(txGasPrice)

// gas
txGas, err := getElem().GetUint64()
txGas, err := values.dequeueValue().GetUint64()
if err != nil {
return err
}

tx.setGas(txGas)

// to
if vv, _ := getElem().Bytes(); len(vv) == 20 {
if vv, _ := values.dequeueValue().Bytes(); len(vv) == 20 {
// address
addr := BytesToAddress(vv)
tx.setTo(&addr)
Expand All @@ -144,7 +138,7 @@ func (tx *LegacyTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

// value
txValue := new(big.Int)
if err = getElem().GetBigInt(txValue); err != nil {
if err = values.dequeueValue().GetBigInt(txValue); err != nil {
return err
}

Expand All @@ -153,7 +147,7 @@ func (tx *LegacyTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error
// input
var txInput []byte

txInput, err = getElem().GetBytes(txInput)
txInput, err = values.dequeueValue().GetBytes(txInput)
if err != nil {
return err
}
Expand All @@ -162,19 +156,19 @@ func (tx *LegacyTx) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

// V
txV := new(big.Int)
if err = getElem().GetBigInt(txV); err != nil {
if err = values.dequeueValue().GetBigInt(txV); err != nil {
return err
}

// R
txR := new(big.Int)
if err = getElem().GetBigInt(txR); err != nil {
if err = values.dequeueValue().GetBigInt(txR); err != nil {
return err
}

// S
txS := new(big.Int)
if err = getElem().GetBigInt(txS); err != nil {
if err = values.dequeueValue().GetBigInt(txS); err != nil {
return err
}

Expand Down
8 changes: 8 additions & 0 deletions types/rlp_unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,11 @@ func (t *Transaction) UnmarshalRLP(input []byte) error {

return nil
}

type rlpValues []*fastrlp.Value

func (r rlpValues) dequeueValue() *fastrlp.Value {
val := r[0]
r = r[1:]

Check failure on line 391 in types/rlp_unmarshal.go

View workflow job for this annotation

GitHub Actions / Linter

assigned to r, but never used afterwards (wastedassign)
return val

Check failure on line 392 in types/rlp_unmarshal.go

View workflow job for this annotation

GitHub Actions / Linter

return with no blank line before (nlreturn)
}
Loading

0 comments on commit fec4957

Please sign in to comment.