Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Introduce marshallTypedTransactionsAsRlpStrings arg into (*Block) Raw…
Browse files Browse the repository at this point in the history
…Body()
  • Loading branch information
yperbasis committed Jul 20, 2022
1 parent 40cdd1f commit 903fca5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,13 +1198,19 @@ func (b *Block) SendersToTxs(senders []common.Address) {
}
}

// RawBody creates a RawBody based on the block. It is not very efficient, so
// will probably be removed in favour of RawBlock. Also it panics
func (b *Block) RawBody() *RawBody {
// RawBody creates a RawBody based on the block.
func (b *Block) RawBody(marshallTypedTransactionsAsRlpStrings bool) *RawBody {
br := &RawBody{Transactions: make([][]byte, len(b.transactions)), Uncles: b.uncles}
for i, tx := range b.transactions {
var err error
br.Transactions[i], err = rlp.EncodeToBytes(tx)
var err error
if marshallTypedTransactionsAsRlpStrings {
for i, tx := range b.transactions {
br.Transactions[i], err = rlp.EncodeToBytes(tx)
if err != nil {
panic(err)
}
}
} else {
br.Transactions, err = MarshalTransactionsBinary(b.transactions)
if err != nil {
panic(err)
}
Expand All @@ -1213,7 +1219,7 @@ func (b *Block) RawBody() *RawBody {
}

// Size returns the true RLP encoded storage size of the block, either by encoding
// and returning it, or returning a previsouly cached value.
// 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)
Expand Down
4 changes: 2 additions & 2 deletions turbo/stages/bodydownload/body_algos.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (bd *BodyDownload) RequestMoreBodies(tx kv.RwTx, blockReader services.FullB
if block := bd.prefetchedBlocks.Pop(hash); block != nil {
// Block is prefetched, no need to request
bd.deliveriesH[blockNum-bd.requestedLow] = block.Header()
bd.deliveriesB[blockNum-bd.requestedLow] = block.RawBody()
bd.deliveriesB[blockNum-bd.requestedLow] = block.RawBody(true)

// Calculate the TD of the block (it's not imported yet, so block.Td is not valid)
if parent, err := rawdb.ReadTd(tx, block.ParentHash(), block.NumberU64()-1); err != nil {
Expand All @@ -155,7 +155,7 @@ func (bd *BodyDownload) RequestMoreBodies(tx kv.RwTx, blockReader services.FullB
copy(doubleHash[common.HashLength:], header.TxHash.Bytes())
bd.requestedMap[doubleHash] = blockNum
} else {
bd.deliveriesB[blockNum-bd.requestedLow] = block.RawBody()
bd.deliveriesB[blockNum-bd.requestedLow] = block.RawBody(true)
request = false
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion turbo/stages/mock_sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func (ms *MockSentry) insertPoSBlocks(chain *core.ChainPack) error {
for i := n; i < chain.Length(); i++ {
payloadMessage := engineapi.PayloadMessage{
Header: chain.Headers[i],
Body: chain.Blocks[i].RawBody(),
Body: chain.Blocks[i].RawBody(false),
}
ms.SendPayloadRequest(&payloadMessage)
}
Expand Down
4 changes: 2 additions & 2 deletions turbo/stages/sentry_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func TestPoSDownloader(t *testing.T) {
// Send a payload with missing parent
payloadMessage := engineapi.PayloadMessage{
Header: chain.TopBlock.Header(),
Body: chain.TopBlock.RawBody(),
Body: chain.TopBlock.RawBody(false),
}
m.SendPayloadRequest(&payloadMessage)
headBlockHash, err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, true, m.UpdateHead, nil)
Expand Down Expand Up @@ -643,7 +643,7 @@ func TestPoSSyncWithInvalidHeader(t *testing.T) {
// Send a payload with missing parent
payloadMessage := engineapi.PayloadMessage{
Header: invalidTip,
Body: chain.TopBlock.RawBody(),
Body: chain.TopBlock.RawBody(false),
}
m.SendPayloadRequest(&payloadMessage)
headBlockHash, err := stages.StageLoopStep(m.Ctx, m.DB, m.Sync, 0, m.Notifications, true, m.UpdateHead, nil)
Expand Down

0 comments on commit 903fca5

Please sign in to comment.