Fix CopyTxs for BlobTxWrapper (EIP-4844) (#8002)

This commit is contained in:
Andrew Ashikhmin 2023-08-11 20:30:02 +02:00 committed by GitHub
parent 8809a4acd3
commit e377cea51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 7 deletions

View File

@ -1594,11 +1594,16 @@ func CopyTxs(in Transactions) Transactions {
if err != nil {
panic(fmt.Errorf("MarshalTransactionsBinary failed: %w", err))
}
out, err := DecodeTransactions(transactionsData)
if err != nil {
panic(fmt.Errorf("DecodeTransactions failed: %w", err))
}
for i := 0; i < len(in); i++ {
out := make([]Transaction, len(in))
for i, tx := range in {
if _, ok := tx.(*BlobTxWrapper); ok {
out[i], err = UnmarshalWrappedTransactionFromBinary(transactionsData[i])
} else {
out[i], err = UnmarshalTransactionFromBinary(transactionsData[i])
}
if err != nil {
panic(fmt.Errorf("DecodeTransactions failed: %w", err))
}
if s, ok := in[i].GetSender(); ok {
out[i].SetSender(s)
}

View File

@ -486,3 +486,29 @@ func TestBlockRawBodyPostShanghaiWithdrawals(t *testing.T) {
require.Equal(0, len(body.Transactions))
require.Equal(2, len(body.Withdrawals))
}
func TestCopyTxs(t *testing.T) {
var txs Transactions
txs = append(txs, &LegacyTx{
CommonTx: CommonTx{
Nonce: 0,
Value: new(uint256.Int).SetUint64(10000),
Gas: 50000,
Data: []byte("Sparta"),
},
GasPrice: new(uint256.Int).SetUint64(10),
})
populateBlobTxs()
for _, tx := range dummyBlobTxs {
txs = append(txs, tx)
}
populateBlobWrapperTxs()
for _, tx := range dummyBlobWrapperTxs {
txs = append(txs, tx)
}
copies := CopyTxs(txs)
assert.Equal(t, txs, copies)
}

View File

@ -19,11 +19,11 @@ func NewLatestBlockBuiltStore() *LatestBlockBuiltStore {
func (s *LatestBlockBuiltStore) AddBlockBuilt(block *types.Block) {
s.lock.Lock()
defer s.lock.Unlock()
s.block = block.Copy()
s.block = block
}
func (s *LatestBlockBuiltStore) BlockBuilt() *types.Block {
s.lock.Lock()
defer s.lock.Unlock()
return s.block.Copy()
return s.block
}