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 4e2909d commit d17ce93
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 222 deletions.
19 changes: 1 addition & 18 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1872,31 +1872,14 @@ func customJSONBlockUnmarshall(tb testing.TB, jsonData []byte) (*types.FullBlock
for _, transactionJSON := range transactionsJSON {
tr := transactionJSON.(map[string]interface{})

var txData types.TxData

txType := tr["type"].(string)

txTypeNumber, err := common.ParseUint64orHex(&txType)
if err != nil {
return nil, err
}

switch types.TxType(txTypeNumber) {
case types.AccessListTxType:
txData = &types.AccessListTxn{}
case types.StateTxType:
txData = &types.DynamicFeeTx{}
case types.LegacyTxType:
txData = &types.LegacyTx{}
default:
txData = &types.DynamicFeeTx{}
}

if txData == nil {
continue
}

transaction := types.NewTx(txData)
transaction := types.NewTxWithType(types.TxType(txTypeNumber))
transaction.SetHash(types.StringToHash(tr["hash"].(string)))
nonce := tr["nonce"].(string)

Expand Down
46 changes: 11 additions & 35 deletions jsonrpc/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ func GetNextNonce(address types.Address, number BlockNumber, store nonceGetter)
}

func DecodeTxn(arg *txnArgs, blockNumber uint64, store nonceGetter, forceSetNonce bool) (*types.Transaction, error) {
var txn *types.Transaction

if arg == nil {
return nil, errors.New("missing value for required argument 0")
}
Expand Down Expand Up @@ -221,44 +219,22 @@ func DecodeTxn(arg *txnArgs, blockNumber uint64, store nonceGetter, forceSetNonc
txType = types.TxType(*arg.Type)
}

txn := types.NewTxWithType(txType)

switch txType {
case types.AccessListTxType:
txn = types.NewTx(&types.AccessListTxn{
From: *arg.From,
Gas: uint64(*arg.Gas),
Value: new(big.Int).SetBytes(*arg.Value),
Input: input,
Nonce: uint64(*arg.Nonce),
})
case types.LegacyTxType:
txn = types.NewTx(&types.LegacyTx{
From: *arg.From,
Gas: uint64(*arg.Gas),
Value: new(big.Int).SetBytes(*arg.Value),
Input: input,
Nonce: uint64(*arg.Nonce),
GasPrice: new(big.Int).SetBytes(*arg.GasPrice),
})
case types.StateTxType:
txn = types.NewTx(&types.StateTx{
From: *arg.From,
Gas: uint64(*arg.Gas),
Value: new(big.Int).SetBytes(*arg.Value),
Input: input,
Nonce: uint64(*arg.Nonce),
})
txn.SetGasPrice(new(big.Int).SetBytes(*arg.GasPrice))
case types.DynamicFeeTxType:
txn = types.NewTx(&types.DynamicFeeTx{
From: *arg.From,
Gas: uint64(*arg.Gas),
GasTipCap: new(big.Int).SetBytes(*arg.GasTipCap),
GasFeeCap: new(big.Int).SetBytes(*arg.GasFeeCap),
Value: new(big.Int).SetBytes(*arg.Value),
Input: input,
Nonce: uint64(*arg.Nonce),
})
txn.SetGasTipCap(new(big.Int).SetBytes(*arg.GasTipCap))
txn.SetGasFeeCap(new(big.Int).SetBytes(*arg.GasFeeCap))
}

txn.SetFrom(*arg.From)
txn.SetGas(uint64(*arg.Gas))
txn.SetValue(new(big.Int).SetBytes(*arg.Value))
txn.SetInput(input)
txn.SetNonce(uint64(*arg.Nonce))

if arg.To != nil {
txn.SetTo(arg.To)
}
Expand Down
2 changes: 1 addition & 1 deletion state/transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestSubGasLimitPrice(t *testing.T) {
t.Parallel()

transition := newTestTransition(tt.preState)
msg := types.NewTx(&types.StateTx{
msg := types.NewTx(&types.LegacyTx{
From: tt.from,
Gas: tt.gas,
GasPrice: big.NewInt(tt.gasPrice),
Expand Down
9 changes: 3 additions & 6 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,10 @@ func (p *TxPool) validateTx(tx *types.Transaction) error {
}
}

// Check if the given tx is not underpriced
if tx.Type() != types.DynamicFeeTxType {
if tx.GetGasPrice(baseFee).Cmp(new(big.Int).SetUint64(p.priceLimit)) < 0 {
metrics.IncrCounter([]string{txPoolMetrics, "underpriced_tx"}, 1)
if tx.GetGasPrice(baseFee).Cmp(new(big.Int).SetUint64(p.priceLimit)) < 0 {
metrics.IncrCounter([]string{txPoolMetrics, "underpriced_tx"}, 1)

return ErrUnderpriced
}
return ErrUnderpriced
}

// Check nonce ordering
Expand Down
49 changes: 12 additions & 37 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,23 @@ func newTx(addr types.Address, nonce, slots uint64, txType types.TxType) *types.
return nil
}

var tx *types.Transaction
tx := types.NewTxWithType(txType)

switch txType {
case types.AccessListTxType:
tx = types.NewTx(&types.AccessListTxn{
From: addr,
Nonce: nonce,
Value: big.NewInt(1),
GasPrice: big.NewInt(0).SetUint64(defaultPriceLimit),
Gas: validGasLimit,
Input: input,
})
case types.LegacyTxType:
tx = types.NewTx(&types.LegacyTx{
From: addr,
Nonce: nonce,
Value: big.NewInt(1),
GasPrice: big.NewInt(0).SetUint64(defaultPriceLimit),
Gas: validGasLimit,
Input: input,
})
case types.StateTxType:
tx = types.NewTx(&types.StateTx{
From: addr,
Nonce: nonce,
Value: big.NewInt(1),
GasPrice: big.NewInt(0).SetUint64(defaultPriceLimit),
Gas: validGasLimit,
Input: input,
})
case types.DynamicFeeTxType:
tx.SetGasFeeCap(big.NewInt(100))
tx.SetGasTipCap(big.NewInt(100))

default:
tx = types.NewTx(&types.DynamicFeeTx{
From: addr,
Nonce: nonce,
Value: big.NewInt(1),
GasTipCap: big.NewInt(100),
GasFeeCap: big.NewInt(100),
Gas: validGasLimit,
Input: input,
})
tx.SetGasPrice(big.NewInt(0).SetUint64(defaultPriceLimit))
}

tx.SetFrom(addr)
tx.SetNonce(nonce)
tx.SetValue(big.NewInt(1))
tx.SetGas(validGasLimit)
tx.SetInput(input)

return tx
}

Expand Down
113 changes: 61 additions & 52 deletions types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,64 @@ func (al TxAccessList) Copy() TxAccessList {
return newAccessList
}

func (al TxAccessList) unmarshallRLPFrom(p *fastrlp.Parser, accessListVV []*fastrlp.Value) error {
for i, accessTupleVV := range accessListVV {
accessTupleElems, err := accessTupleVV.GetElems()
if err != nil {
return err
}

// Read the address
addressVV := accessTupleElems[0]

addressBytes, err := addressVV.Bytes()
if err != nil {
return err
}

al[i].Address = BytesToAddress(addressBytes)

// Read the storage keys
storageKeysArrayVV := accessTupleElems[1]

storageKeysElems, err := storageKeysArrayVV.GetElems()
if err != nil {
return err
}

al[i].StorageKeys = make([]Hash, len(storageKeysElems))

for j, storageKeyVV := range storageKeysElems {
storageKeyBytes, err := storageKeyVV.Bytes()
if err != nil {
return err
}

al[i].StorageKeys[j] = BytesToHash(storageKeyBytes)
}
}

return nil
}

func (al TxAccessList) marshallRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
accessListVV := arena.NewArray()

for _, accessTuple := range al {
accessTupleVV := arena.NewArray()
accessTupleVV.Set(arena.NewCopyBytes(accessTuple.Address.Bytes()))

storageKeysVV := arena.NewArray()
for _, storageKey := range accessTuple.StorageKeys {
storageKeysVV.Set(arena.NewCopyBytes(storageKey.Bytes()))
}

accessTupleVV.Set(storageKeysVV)
accessListVV.Set(accessTupleVV)
}
return accessListVV
}

type AccessListTxn struct {
Nonce uint64
GasPrice *big.Int
Expand Down Expand Up @@ -233,41 +291,7 @@ func (tx *AccessListTxn) unmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) e
txAccessList = make(TxAccessList, len(accessListVV))
}

for i, accessTupleVV := range accessListVV {
accessTupleElems, err := accessTupleVV.GetElems()
if err != nil {
return err
}

// Read the address
addressVV := accessTupleElems[0]

addressBytes, err := addressVV.Bytes()
if err != nil {
return err
}

txAccessList[i].Address = BytesToAddress(addressBytes)

// Read the storage keys
storageKeysArrayVV := accessTupleElems[1]

storageKeysElems, err := storageKeysArrayVV.GetElems()
if err != nil {
return err
}

txAccessList[i].StorageKeys = make([]Hash, len(storageKeysElems))

for j, storageKeyVV := range storageKeysElems {
storageKeyBytes, err := storageKeyVV.Bytes()
if err != nil {
return err
}

txAccessList[i].StorageKeys[j] = BytesToHash(storageKeyBytes)
}
}
txAccessList.unmarshallRLPFrom(p, accessListVV)

tx.setAccessList(txAccessList)

Expand Down Expand Up @@ -315,23 +339,8 @@ func (tx *AccessListTxn) marshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value {
vv.Set(arena.NewBigInt(tx.value()))
vv.Set(arena.NewCopyBytes(tx.input()))

// add accessList
accessListVV := arena.NewArray()

for _, accessTuple := range tx.accessList() {
accessTupleVV := arena.NewArray()
accessTupleVV.Set(arena.NewCopyBytes(accessTuple.Address.Bytes()))

storageKeysVV := arena.NewArray()
for _, storageKey := range accessTuple.StorageKeys {
storageKeysVV.Set(arena.NewCopyBytes(storageKey.Bytes()))
}

accessTupleVV.Set(storageKeysVV)
accessListVV.Set(accessTupleVV)
}

vv.Set(accessListVV)
// Convert TxAccessList to RLP format and add it to the vv array.
vv.Set(tx.accessList().marshallRLPWith(arena))

v, r, s := tx.rawSignatureValues()
vv.Set(arena.NewBigInt(v))
Expand Down
Loading

0 comments on commit d17ce93

Please sign in to comment.