Skip to content

Commit

Permalink
Fix CopyTxs for BlobTxWrapper (EIP-4844) (#8002)
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis authored and AskAlexSharov committed Sep 6, 2023
1 parent 628b7f4 commit 745a918
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
15 changes: 10 additions & 5 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
26 changes: 26 additions & 0 deletions core/types/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions turbo/builder/latest_block_built.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 745a918

Please sign in to comment.