From ecb0926103e89c01c9d4231578e68ff86ce8aff4 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 11:47:03 +0700 Subject: [PATCH 1/7] save --- core/types/access_list_tx.go | 26 +++++++++------------- core/types/blob_tx.go | 13 +++++------ core/types/blob_tx_wrapper.go | 4 ---- core/types/block.go | 41 +++++++++++++---------------------- core/types/dynamic_fee_tx.go | 28 ++++++++++-------------- core/types/legacy_tx.go | 28 ++++++++---------------- core/types/set_code_tx.go | 12 +--------- core/types/transaction.go | 5 ++--- 8 files changed, 54 insertions(+), 103 deletions(-) diff --git a/core/types/access_list_tx.go b/core/types/access_list_tx.go index a14873353de..90f54aebeff 100644 --- a/core/types/access_list_tx.go +++ b/core/types/access_list_tx.go @@ -34,7 +34,6 @@ import ( rlp2 "github.com/erigontech/erigon-lib/rlp" types2 "github.com/erigontech/erigon-lib/types" - "github.com/erigontech/erigon/common/u256" "github.com/erigontech/erigon/rlp" ) @@ -449,19 +448,11 @@ func (tx *AccessListTx) WithSignature(signer Signer, sig []byte) (Transaction, e cpy.ChainID = signer.ChainID() return cpy, nil } -func (tx *AccessListTx) FakeSign(address libcommon.Address) Transaction { - cpy := tx.copy() - cpy.R.Set(u256.Num1) - cpy.S.Set(u256.Num1) - cpy.V.Set(u256.Num4) - cpy.from.Store(address) - return cpy -} // Hash computes the hash (but not for signatures!) func (tx *AccessListTx) Hash() libcommon.Hash { if hash := tx.hash.Load(); hash != nil { - return *hash.(*libcommon.Hash) + return *hash } hash := prefixedRlpHash(AccessListTxType, []interface{}{ tx.ChainID, @@ -508,19 +499,22 @@ func (tx *AccessListTx) cachedSender() (sender libcommon.Address, ok bool) { if s == nil { return sender, false } - return s.(libcommon.Address), true + return *s, true } + +var zeroAddr = libcommon.Address{} + func (tx *AccessListTx) Sender(signer Signer) (libcommon.Address, error) { - if sc := tx.from.Load(); sc != nil { - zeroAddr := libcommon.Address{} - if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer - return sc.(libcommon.Address), nil + if from := tx.from.Load(); from != nil { + if *from != zeroAddr { // Sender address can never be zero in a transaction with a valid signer + return *from, nil } } + addr, err := signer.Sender(tx) if err != nil { return libcommon.Address{}, err } - tx.from.Store(addr) + tx.from.Store(&addr) return addr, nil } diff --git a/core/types/blob_tx.go b/core/types/blob_tx.go index a2f4f78a660..57f1c23c2d4 100644 --- a/core/types/blob_tx.go +++ b/core/types/blob_tx.go @@ -101,27 +101,26 @@ func (stx *BlobTx) cachedSender() (sender libcommon.Address, ok bool) { if s == nil { return sender, false } - return s.(libcommon.Address), true + return *s, true } func (stx *BlobTx) Sender(signer Signer) (libcommon.Address, error) { - if sc := stx.from.Load(); sc != nil { - zeroAddr := libcommon.Address{} - if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer - return sc.(libcommon.Address), nil + if from := stx.from.Load(); from != nil { + if *from != zeroAddr { // Sender address can never be zero in a transaction with a valid signer + return *from, nil } } addr, err := signer.Sender(stx) if err != nil { return libcommon.Address{}, err } - stx.from.Store(addr) + stx.from.Store(&addr) return addr, nil } func (stx *BlobTx) Hash() libcommon.Hash { if hash := stx.hash.Load(); hash != nil { - return *hash.(*libcommon.Hash) + return *hash } hash := prefixedRlpHash(BlobTxType, []interface{}{ stx.ChainID, diff --git a/core/types/blob_tx_wrapper.go b/core/types/blob_tx_wrapper.go index 0a914c065f1..9e8e99a2c23 100644 --- a/core/types/blob_tx_wrapper.go +++ b/core/types/blob_tx_wrapper.go @@ -328,10 +328,6 @@ func (txw *BlobTxWrapper) WithSignature(signer Signer, sig []byte) (Transaction, return txw.Tx.WithSignature(signer, sig) } -func (txw *BlobTxWrapper) FakeSign(address libcommon.Address) Transaction { - return txw.Tx.FakeSign(address) -} - func (txw *BlobTxWrapper) Hash() libcommon.Hash { return txw.Tx.Hash() } func (txw *BlobTxWrapper) SigningHash(chainID *big.Int) libcommon.Hash { diff --git a/core/types/block.go b/core/types/block.go index d379550f274..4840256a5df 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -719,8 +719,8 @@ type Block struct { requests Requests // caches - hash atomic.Value - size atomic.Value + hash atomic.Pointer[libcommon.Hash] + size atomic.Uint64 } // Copy transaction senders from body into the transactions @@ -1100,7 +1100,7 @@ func NewBlock(header *Header, txs []Transaction, uncles []*Header, receipts []*R // in this case no reason to copy parts, or re-calculate headers fields - they are all stored in DB func NewBlockFromStorage(hash libcommon.Hash, header *Header, txs []Transaction, uncles []*Header, withdrawals []*Withdrawal, requests Requests) *Block { b := &Block{header: header, transactions: txs, uncles: uncles, withdrawals: withdrawals, requests: requests} - b.hash.Store(hash) + b.hash.Store(&hash) return b } @@ -1174,7 +1174,7 @@ func (bb *Block) DecodeRLP(s *rlp.Stream) error { if err != nil { return err } - bb.size.Store(common.StorageSize(rlp.ListSize(size))) + bb.size.Store(rlp.ListSize(size)) // decode header var h Header @@ -1362,12 +1362,12 @@ func (b *Body) RawBody() *RawBody { // Size returns the true RLP encoded storage size of the block, either by encoding // and returning it, or returning a previously cached value. func (b *Block) Size() common.StorageSize { - if size := b.size.Load(); size != nil { - return size.(common.StorageSize) + if size := b.size.Load(); size > 0 { + return common.StorageSize(size) } c := writeCounter(0) rlp.Encode(&c, b) - b.size.Store(common.StorageSize(c)) + b.size.Store(uint64(c)) return common.StorageSize(c) } @@ -1484,27 +1484,16 @@ func (b *Block) Copy() *Block { } } - var hashValue atomic.Value - if value := b.hash.Load(); value != nil { - hash := value.(libcommon.Hash) - hashCopy := libcommon.BytesToHash(hash.Bytes()) - hashValue.Store(hashCopy) - } - - var sizeValue atomic.Value - if size := b.size.Load(); size != nil { - sizeValue.Store(size) - } - - return &Block{ + newB := &Block{ header: CopyHeader(b.header), uncles: uncles, transactions: CopyTxs(b.transactions), withdrawals: withdrawals, requests: requests, - hash: hashValue, - size: sizeValue, } + newB.hash.Store(b.hash.Load()) + newB.size.Store(b.size.Load()) + return newB } // WithSeal returns a new block with the data from b but the header replaced with @@ -1525,11 +1514,11 @@ func (b *Block) WithSeal(header *Header) *Block { // The hash is computed on the first call and cached thereafter. func (b *Block) Hash() libcommon.Hash { if hash := b.hash.Load(); hash != nil { - return hash.(libcommon.Hash) + return *hash } - v := b.header.Hash() - b.hash.Store(v) - return v + h := b.header.Hash() + b.hash.Store(&h) + return h } type Blocks []*Block diff --git a/core/types/dynamic_fee_tx.go b/core/types/dynamic_fee_tx.go index 38b787bd7e6..b76fe869698 100644 --- a/core/types/dynamic_fee_tx.go +++ b/core/types/dynamic_fee_tx.go @@ -32,7 +32,6 @@ import ( rlp2 "github.com/erigontech/erigon-lib/rlp" types2 "github.com/erigontech/erigon-lib/types" - "github.com/erigontech/erigon/common/u256" "github.com/erigontech/erigon/rlp" ) @@ -170,15 +169,6 @@ func (tx *DynamicFeeTransaction) WithSignature(signer Signer, sig []byte) (Trans return cpy, nil } -func (tx *DynamicFeeTransaction) FakeSign(address libcommon.Address) Transaction { - cpy := tx.copy() - cpy.R.Set(u256.Num1) - cpy.S.Set(u256.Num1) - cpy.V.Set(u256.Num4) - cpy.from.Store(address) - return cpy -} - // MarshalBinary returns the canonical encoding of the transaction. // For legacy transactions, it returns the RLP encoding. For EIP-2718 typed // transactions, it returns the type and payload. @@ -374,7 +364,7 @@ func (tx *DynamicFeeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *ch // Hash computes the hash (but not for signatures!) func (tx *DynamicFeeTransaction) Hash() libcommon.Hash { if hash := tx.hash.Load(); hash != nil { - return *hash.(*libcommon.Hash) + return *hash } hash := prefixedRlpHash(DynamicFeeTxType, []interface{}{ tx.ChainID, @@ -424,20 +414,24 @@ func (tx *DynamicFeeTransaction) cachedSender() (sender libcommon.Address, ok bo if s == nil { return sender, false } - return s.(libcommon.Address), true + return s.from, true } func (tx *DynamicFeeTransaction) Sender(signer Signer) (libcommon.Address, error) { - if sc := tx.from.Load(); sc != nil { - zeroAddr := libcommon.Address{} - if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer - return sc.(libcommon.Address), nil + if sigCache := tx.from.Load(); sigCache != nil { + // If the signer used to derive from in a previous + // call is not the same as used current, invalidate + // the cache. + if sigCache.signer.Equal(signer) { + if sigCache.from != zeroAddr { // Sender address can never be zero in a transaction with a valid signer + return sigCache.from, nil + } } } addr, err := signer.Sender(tx) if err != nil { return libcommon.Address{}, err } - tx.from.Store(addr) + tx.from.Store(&sigCache{signer: signer, from: addr}) return addr, nil } diff --git a/core/types/legacy_tx.go b/core/types/legacy_tx.go index b44e9c2df8e..8a3fe25b68d 100644 --- a/core/types/legacy_tx.go +++ b/core/types/legacy_tx.go @@ -32,7 +32,6 @@ import ( rlp2 "github.com/erigontech/erigon-lib/rlp" types2 "github.com/erigontech/erigon-lib/types" - "github.com/erigontech/erigon/common/u256" "github.com/erigontech/erigon/rlp" ) @@ -73,13 +72,13 @@ func (ct *CommonTx) GetData() []byte { func (ct *CommonTx) GetSender() (libcommon.Address, bool) { if sc := ct.from.Load(); sc != nil { - return sc.(libcommon.Address), true + return *sc, true } return libcommon.Address{}, false } func (ct *CommonTx) SetSender(addr libcommon.Address) { - ct.from.Store(addr) + ct.from.Store(&addr) } func (ct *CommonTx) Protected() bool { @@ -376,19 +375,10 @@ func (tx *LegacyTx) WithSignature(signer Signer, sig []byte) (Transaction, error return cpy, nil } -func (tx *LegacyTx) FakeSign(address libcommon.Address) Transaction { - cpy := tx.copy() - cpy.R.Set(u256.Num1) - cpy.S.Set(u256.Num1) - cpy.V.Set(u256.Num4) - cpy.from.Store(address) - return cpy -} - // Hash computes the hash (but not for signatures!) func (tx *LegacyTx) Hash() libcommon.Hash { if hash := tx.hash.Load(); hash != nil { - return *hash.(*libcommon.Hash) + return *hash } hash := rlpHash([]interface{}{ tx.Nonce, @@ -440,19 +430,19 @@ func (tx *LegacyTx) cachedSender() (sender libcommon.Address, ok bool) { if s == nil { return sender, false } - return s.(libcommon.Address), true + return *s, true } func (tx *LegacyTx) Sender(signer Signer) (libcommon.Address, error) { - if sc := tx.from.Load(); sc != nil { - zeroAddr := libcommon.Address{} - if sc.(libcommon.Address) != zeroAddr { // Sender address can never be zero in a transaction with a valid signer - return sc.(libcommon.Address), nil + if from := tx.from.Load(); from != nil { + if *from != zeroAddr { // Sender address can never be zero in a transaction with a valid signer + return *from, nil } } + addr, err := signer.Sender(tx) if err != nil { return libcommon.Address{}, err } - tx.from.Store(addr) + tx.from.Store(&addr) return addr, nil } diff --git a/core/types/set_code_tx.go b/core/types/set_code_tx.go index aeb0f71d10a..f725dcf4886 100644 --- a/core/types/set_code_tx.go +++ b/core/types/set_code_tx.go @@ -12,7 +12,6 @@ import ( libcommon "github.com/erigontech/erigon-lib/common" rlp2 "github.com/erigontech/erigon-lib/rlp" types2 "github.com/erigontech/erigon-lib/types" - "github.com/erigontech/erigon/common/u256" "github.com/erigontech/erigon/rlp" ) @@ -79,15 +78,6 @@ func (tx *SetCodeTransaction) WithSignature(signer Signer, sig []byte) (Transact return cpy, nil } -func (tx *SetCodeTransaction) FakeSign(address libcommon.Address) Transaction { - cpy := tx.copy() - cpy.R.Set(u256.Num1) - cpy.S.Set(u256.Num1) - cpy.V.Set(u256.Num4) - cpy.from.Store(address) - return cpy -} - func (tx *SetCodeTransaction) MarshalBinary(w io.Writer) error { payloadSize, nonceLen, gasLen, accessListLen, authorizationsLen := tx.payloadSize() var b [33]byte @@ -117,7 +107,7 @@ func (tx *SetCodeTransaction) AsMessage(s Signer, baseFee *big.Int, rules *chain func (tx *SetCodeTransaction) Hash() libcommon.Hash { if hash := tx.hash.Load(); hash != nil { - return *hash.(*libcommon.Hash) + return *hash } hash := prefixedRlpHash(SetCodeTxType, []interface{}{ tx.ChainID, diff --git a/core/types/transaction.go b/core/types/transaction.go index a5be3bef561..2e78009c6d8 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -74,7 +74,6 @@ type Transaction interface { GetTo() *libcommon.Address AsMessage(s Signer, baseFee *big.Int, rules *chain.Rules) (Message, error) WithSignature(signer Signer, sig []byte) (Transaction, error) - FakeSign(address libcommon.Address) Transaction Hash() libcommon.Hash SigningHash(chainID *big.Int) libcommon.Hash GetData() []byte @@ -104,8 +103,8 @@ type Transaction interface { // implementations of different transaction types type TransactionMisc struct { // caches - hash atomic.Value //nolint:structcheck - from atomic.Value + hash atomic.Pointer[libcommon.Hash] + from atomic.Pointer[libcommon.Address] } // RLP-marshalled legacy transactions and binary-marshalled (not wrapped into an RLP string) typed (EIP-2718) transactions From 5a2ddea0c42c63644c91c716299b69109613cb6c Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 11:47:24 +0700 Subject: [PATCH 2/7] save --- core/types/dynamic_fee_tx.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/core/types/dynamic_fee_tx.go b/core/types/dynamic_fee_tx.go index b76fe869698..31d4d4799e9 100644 --- a/core/types/dynamic_fee_tx.go +++ b/core/types/dynamic_fee_tx.go @@ -414,24 +414,19 @@ func (tx *DynamicFeeTransaction) cachedSender() (sender libcommon.Address, ok bo if s == nil { return sender, false } - return s.from, true + return *s, true } func (tx *DynamicFeeTransaction) Sender(signer Signer) (libcommon.Address, error) { - if sigCache := tx.from.Load(); sigCache != nil { - // If the signer used to derive from in a previous - // call is not the same as used current, invalidate - // the cache. - if sigCache.signer.Equal(signer) { - if sigCache.from != zeroAddr { // Sender address can never be zero in a transaction with a valid signer - return sigCache.from, nil - } + if from := tx.from.Load(); from != nil { + if *from != zeroAddr { // Sender address can never be zero in a transaction with a valid signer + return *from, nil } } addr, err := signer.Sender(tx) if err != nil { return libcommon.Address{}, err } - tx.from.Store(&sigCache{signer: signer, from: addr}) + tx.from.Store(&addr) return addr, nil } From cfd4d1387716ae314cb50b9d25e3c9e9ef9dedd2 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 12:22:22 +0700 Subject: [PATCH 3/7] save --- core/types/blob_tx_wrapper.go | 5 ++--- core/types/block.go | 6 +++--- core/types/transaction_marshalling.go | 5 +---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/core/types/blob_tx_wrapper.go b/core/types/blob_tx_wrapper.go index 9e8e99a2c23..89454389272 100644 --- a/core/types/blob_tx_wrapper.go +++ b/core/types/blob_tx_wrapper.go @@ -273,8 +273,7 @@ func (c KZGCommitment) ComputeVersionedHash() libcommon.Hash { // validateBlobTransactionWrapper implements validate_blob_transaction_wrapper from EIP-4844 func (txw *BlobTxWrapper) ValidateBlobTransactionWrapper() error { - blobTx := txw.Tx - l1 := len(blobTx.BlobVersionedHashes) + l1 := len(txw.Tx.BlobVersionedHashes) if l1 == 0 { return errors.New("a blob txn must contain at least one blob") } @@ -295,7 +294,7 @@ func (txw *BlobTxWrapper) ValidateBlobTransactionWrapper() error { if err != nil { return fmt.Errorf("error during proof verification: %v", err) } - for i, h := range blobTx.BlobVersionedHashes { + for i, h := range txw.Tx.BlobVersionedHashes { if computed := txw.Commitments[i].ComputeVersionedHash(); computed != h { return fmt.Errorf("versioned hash %d supposedly %s but does not match computed %s", i, h, computed) } diff --git a/core/types/block.go b/core/types/block.go index 4840256a5df..1abcc201acb 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -1204,7 +1204,7 @@ func (bb *Block) DecodeRLP(s *rlp.Stream) error { return s.ListEnd() } -func (bb Block) payloadSize() (payloadSize int, txsLen, unclesLen, withdrawalsLen, requestsLen int) { +func (bb *Block) payloadSize() (payloadSize int, txsLen, unclesLen, withdrawalsLen, requestsLen int) { // size of Header headerLen := bb.header.EncodingSize() payloadSize += rlp2.ListPrefixLen(headerLen) + headerLen @@ -1233,13 +1233,13 @@ func (bb Block) payloadSize() (payloadSize int, txsLen, unclesLen, withdrawalsLe return payloadSize, txsLen, unclesLen, withdrawalsLen, requestsLen } -func (bb Block) EncodingSize() int { +func (bb *Block) EncodingSize() int { payloadSize, _, _, _, _ := bb.payloadSize() return payloadSize } // EncodeRLP serializes b into the Ethereum RLP block format. -func (bb Block) EncodeRLP(w io.Writer) error { +func (bb *Block) EncodeRLP(w io.Writer) error { payloadSize, txsLen, unclesLen, withdrawalsLen, _ /* requestsLen */ := bb.payloadSize() var b [33]byte // prefix diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index d95cca228e1..bb110401332 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -494,12 +494,9 @@ func (tx *SetCodeTransaction) UnmarshalJSON(input []byte) error { return err } - dTx := DynamicFeeTransaction{} - if err := dTx.unmarshalJson(dec); err != nil { + if err := tx.DynamicFeeTransaction.unmarshalJson(dec); err != nil { return err } - - tx.DynamicFeeTransaction = dTx tx.Authorizations = make([]Authorization, len(*dec.Authorizations)) for i, auth := range *dec.Authorizations { tx.Authorizations[i] = auth.ToAuthorization() From 5993dae69f99cb8937565967e12f3cf5b9981205 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 12:28:21 +0700 Subject: [PATCH 4/7] save --- core/types/encdec_test.go | 10 +++++----- core/types/transaction_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/types/encdec_test.go b/core/types/encdec_test.go index 2270a81921a..c6f1559176a 100644 --- a/core/types/encdec_test.go +++ b/core/types/encdec_test.go @@ -208,13 +208,13 @@ func (tr *TRand) RandTransaction() Transaction { switch txType { case LegacyTxType: return &LegacyTx{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint GasPrice: uint256.NewInt(*tr.RandUint64()), } case AccessListTxType: return &AccessListTx{ LegacyTx: LegacyTx{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint GasPrice: uint256.NewInt(*tr.RandUint64()), }, ChainID: uint256.NewInt(*tr.RandUint64()), @@ -222,7 +222,7 @@ func (tr *TRand) RandTransaction() Transaction { } case DynamicFeeTxType: return &DynamicFeeTransaction{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint ChainID: uint256.NewInt(*tr.RandUint64()), Tip: uint256.NewInt(*tr.RandUint64()), FeeCap: uint256.NewInt(*tr.RandUint64()), @@ -232,7 +232,7 @@ func (tr *TRand) RandTransaction() Transaction { r := *tr.RandUint64() return &BlobTx{ DynamicFeeTransaction: DynamicFeeTransaction{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint ChainID: uint256.NewInt(*tr.RandUint64()), Tip: uint256.NewInt(*tr.RandUint64()), FeeCap: uint256.NewInt(*tr.RandUint64()), @@ -244,7 +244,7 @@ func (tr *TRand) RandTransaction() Transaction { case SetCodeTxType: return &SetCodeTransaction{ DynamicFeeTransaction: DynamicFeeTransaction{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint ChainID: uint256.NewInt(*tr.RandUint64()), Tip: uint256.NewInt(*tr.RandUint64()), FeeCap: uint256.NewInt(*tr.RandUint64()), diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 60d4ecac042..4507048c4c5 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -692,10 +692,10 @@ func newRandBlobs(size int) Blobs { } func newRandBlobWrapper() *BlobTxWrapper { - btxw := *newRandBlobTx() + btxw := newRandBlobTx() l := len(btxw.BlobVersionedHashes) return &BlobTxWrapper{ - Tx: btxw, + Tx: *btxw, //nolint Commitments: newRandCommitments(l), Blobs: newRandBlobs(l), Proofs: newRandProofs(l), From 351e003799cf4e594c985a2437fba1c335235a8c Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 12:34:59 +0700 Subject: [PATCH 5/7] save --- cmd/evm/internal/t8ntool/transition.go | 8 ++++---- core/types/transaction_marshalling.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 1a0d89647e2..414b0c10e8b 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -429,7 +429,7 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { commonTx.S.SetFromBig(txJson.S.ToInt()) if txJson.Type == types.LegacyTxType || txJson.Type == types.AccessListTxType { legacyTx := types.LegacyTx{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet GasPrice: gasPrice, } @@ -438,7 +438,7 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { } return &types.AccessListTx{ - LegacyTx: legacyTx, + LegacyTx: legacyTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet ChainID: chainId, AccessList: *txJson.Accesses, }, nil @@ -460,7 +460,7 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { } dynamicFeeTx := types.DynamicFeeTransaction{ - CommonTx: commonTx, + CommonTx: commonTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet ChainID: chainId, Tip: tip, FeeCap: feeCap, @@ -477,7 +477,7 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { } return &types.SetCodeTransaction{ - DynamicFeeTransaction: dynamicFeeTx, + DynamicFeeTransaction: dynamicFeeTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet Authorizations: auths, }, nil } else { diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index bb110401332..ef1072b7aa1 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -608,7 +608,7 @@ func UnmarshalBlobTxJSON(input []byte) (Transaction, error) { } btx := BlobTxWrapper{ - Tx: tx, + Tx: tx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet Commitments: dec.Commitments, Blobs: dec.Blobs, Proofs: dec.Proofs, From c00bedc853beffe0980b5a42f4d0bc96f099be85 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 12:57:52 +0700 Subject: [PATCH 6/7] save --- cmd/evm/internal/t8ntool/transition.go | 12 ++++++++---- core/types/block.go | 3 ++- core/types/transaction_marshalling.go | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 414b0c10e8b..2a259960ef9 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -429,7 +429,8 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { commonTx.S.SetFromBig(txJson.S.ToInt()) if txJson.Type == types.LegacyTxType || txJson.Type == types.AccessListTxType { legacyTx := types.LegacyTx{ - CommonTx: commonTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet + //it's ok to copy here - because it's constructor of object - no parallel access yet + CommonTx: commonTx, //nolint GasPrice: gasPrice, } @@ -438,7 +439,8 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { } return &types.AccessListTx{ - LegacyTx: legacyTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet + //it's ok to copy here - because it's constructor of object - no parallel access yet + LegacyTx: legacyTx, //nolint ChainID: chainId, AccessList: *txJson.Accesses, }, nil @@ -460,7 +462,8 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { } dynamicFeeTx := types.DynamicFeeTransaction{ - CommonTx: commonTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet + //it's ok to copy here - because it's constructor of object - no parallel access yet + CommonTx: commonTx, //nolint ChainID: chainId, Tip: tip, FeeCap: feeCap, @@ -477,7 +480,8 @@ func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { } return &types.SetCodeTransaction{ - DynamicFeeTransaction: dynamicFeeTx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet + // it's ok to copy here - because it's constructor of object - no parallel access yet + DynamicFeeTransaction: dynamicFeeTx, //nolint Authorizations: auths, }, nil } else { diff --git a/core/types/block.go b/core/types/block.go index 1abcc201acb..abbe334dfac 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -1450,7 +1450,8 @@ func CopyTxs(in Transactions) Transactions { if txWrapper, ok := txn.(*BlobTxWrapper); ok { blobTx := out[i].(*BlobTx) out[i] = &BlobTxWrapper{ - Tx: *blobTx, + // it's ok to copy here - because it's constructor of object - no parallel access yet + Tx: *blobTx, //nolint Commitments: txWrapper.Commitments.copy(), Blobs: txWrapper.Blobs.copy(), Proofs: txWrapper.Proofs.copy(), diff --git a/core/types/transaction_marshalling.go b/core/types/transaction_marshalling.go index ef1072b7aa1..de1ad3d85e4 100644 --- a/core/types/transaction_marshalling.go +++ b/core/types/transaction_marshalling.go @@ -608,7 +608,8 @@ func UnmarshalBlobTxJSON(input []byte) (Transaction, error) { } btx := BlobTxWrapper{ - Tx: tx, //nolint:govet it's ok to copy here - because it's constructor of object - no parallel access yet + // it's ok to copy here - because it's constructor of object - no parallel access yet + Tx: tx, //nolint Commitments: dec.Commitments, Blobs: dec.Blobs, Proofs: dec.Proofs, From 8b3113f0ae063f666a45801debfac2ddb8d07da5 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Aug 2024 15:19:49 +0700 Subject: [PATCH 7/7] save --- core/types/block.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index abbe334dfac..5c01392674e 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -1492,8 +1492,12 @@ func (b *Block) Copy() *Block { withdrawals: withdrawals, requests: requests, } - newB.hash.Store(b.hash.Load()) - newB.size.Store(b.size.Load()) + if h := b.hash.Load(); h != nil { + hashCopy := *h + newB.hash.Store(&hashCopy) + } + szCopy := b.size.Load() + newB.size.Store(szCopy) return newB }