Skip to content

Commit bbc565a

Browse files
authored
core/types, params: add blob transaction type, RLP encoded for now (#27049)
* core/types, params: add blob transaction type, RLP encoded for now * all: integrate Cancun (and timestamp based forks) into MakeSigner * core/types: fix 2 back-and-forth type refactors * core: fix review comment * core/types: swap blob tx type id to 0x03
1 parent 4ab4e4f commit bbc565a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+448
-115
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
684684
return fmt.Errorf("could not fetch parent")
685685
}
686686
// Check transaction validity
687-
signer := types.MakeSigner(b.blockchain.Config(), block.Number())
687+
signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time())
688688
sender, err := types.Sender(signer, tx)
689689
if err != nil {
690690
return fmt.Errorf("invalid transaction: %v", err)
@@ -884,7 +884,11 @@ func (fb *filterBackend) GetReceipts(ctx context.Context, hash common.Hash) (typ
884884
if number == nil {
885885
return nil, nil
886886
}
887-
return rawdb.ReadReceipts(fb.db, hash, *number, fb.bc.Config()), nil
887+
header := rawdb.ReadHeader(fb.db, hash, *number)
888+
if header == nil {
889+
return nil, nil
890+
}
891+
return rawdb.ReadReceipts(fb.db, hash, *number, header.Time, fb.bc.Config()), nil
888892
}
889893

890894
func (fb *filterBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) {

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
125125
}
126126
var (
127127
statedb = MakePreState(rawdb.NewMemoryDatabase(), pre.Pre)
128-
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number))
128+
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
129129
gaspool = new(core.GasPool)
130130
blockHash = common.Hash{0x13, 0x37}
131131
rejectedTxs []*rejectedTx

cmd/evm/internal/t8ntool/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func Transaction(ctx *cli.Context) error {
112112
return NewError(ErrorIO, errors.New("only rlp supported"))
113113
}
114114
}
115-
signer := types.MakeSigner(chainConfig, new(big.Int))
115+
signer := types.MakeSigner(chainConfig, new(big.Int), 0)
116116
// We now have the transactions in 'body', which is supposed to be an
117117
// rlp list of transactions
118118
it, err := rlp.NewListIterator([]byte(body))

cmd/evm/internal/t8ntool/transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func Transition(ctx *cli.Context) error {
240240
}
241241
}
242242
// We may have to sign the transactions.
243-
signer := types.MakeSigner(chainConfig, big.NewInt(int64(prestate.Env.Number)))
243+
signer := types.MakeSigner(chainConfig, big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp)
244244

245245
if txs, err = signUnsignedTransactions(txsWithKeys, signer); err != nil {
246246
return NewError(ErrorJson, fmt.Errorf("failed signing transactions: %v", err))

core/bench_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
8484
toaddr := common.Address{}
8585
data := make([]byte, nbytes)
8686
gas, _ := IntrinsicGas(data, nil, false, false, false, false)
87-
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)))
87+
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)), gen.header.Time)
8888
gasPrice := big.NewInt(0)
8989
if gen.header.BaseFee != nil {
9090
gasPrice = gen.header.BaseFee
@@ -128,7 +128,7 @@ func genTxRing(naccounts int) func(int, *BlockGen) {
128128
if gen.header.BaseFee != nil {
129129
gasPrice = gen.header.BaseFee
130130
}
131-
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)))
131+
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)), gen.header.Time)
132132
for {
133133
gas -= params.TxGas
134134
if gas < params.TxGas {
@@ -317,7 +317,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
317317
if full {
318318
hash := header.Hash()
319319
rawdb.ReadBody(db, hash, n)
320-
rawdb.ReadReceipts(db, hash, n, chain.Config())
320+
rawdb.ReadReceipts(db, hash, n, header.Time, chain.Config())
321321
}
322322
}
323323
chain.Stop()

core/blockchain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
15401540
}
15411541

15421542
// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss)
1543-
SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number()), chain)
1543+
SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain)
15441544

15451545
var (
15461546
stats = insertStats{startTime: mclock.Now()}
@@ -2049,7 +2049,7 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error)
20492049
// the processing of a block. These logs are later announced as deleted or reborn.
20502050
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
20512051
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
2052-
receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.BaseFee(), b.Transactions())
2052+
receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), b.Transactions())
20532053

20542054
var logs []*types.Log
20552055
for _, receipt := range receipts {

core/blockchain_reader.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts {
217217
if number == nil {
218218
return nil
219219
}
220-
receipts := rawdb.ReadReceipts(bc.db, hash, *number, bc.chainConfig)
220+
header := bc.GetHeader(hash, *number)
221+
if header == nil {
222+
return nil
223+
}
224+
receipts := rawdb.ReadReceipts(bc.db, hash, *number, header.Time, bc.chainConfig)
221225
if receipts == nil {
222226
return nil
223227
}

core/blockchain_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ func TestFastVsFullChains(t *testing.T) {
809809

810810
// Iterate over all chain data components, and cross reference
811811
for i := 0; i < len(blocks); i++ {
812-
num, hash := blocks[i].NumberU64(), blocks[i].Hash()
812+
num, hash, time := blocks[i].NumberU64(), blocks[i].Hash(), blocks[i].Time()
813813

814814
if ftd, atd := fast.GetTd(hash, num), archive.GetTd(hash, num); ftd.Cmp(atd) != 0 {
815815
t.Errorf("block #%d [%x]: td mismatch: fastdb %v, archivedb %v", num, hash, ftd, atd)
@@ -832,9 +832,9 @@ func TestFastVsFullChains(t *testing.T) {
832832
}
833833

834834
// Check receipts.
835-
freceipts := rawdb.ReadReceipts(fastDb, hash, num, fast.Config())
836-
anreceipts := rawdb.ReadReceipts(ancientDb, hash, num, fast.Config())
837-
areceipts := rawdb.ReadReceipts(archiveDb, hash, num, fast.Config())
835+
freceipts := rawdb.ReadReceipts(fastDb, hash, num, time, fast.Config())
836+
anreceipts := rawdb.ReadReceipts(ancientDb, hash, num, time, fast.Config())
837+
areceipts := rawdb.ReadReceipts(archiveDb, hash, num, time, fast.Config())
838838
if types.DeriveSha(freceipts, trie.NewStackTrie(nil)) != types.DeriveSha(areceipts, trie.NewStackTrie(nil)) {
839839
t.Errorf("block #%d [%x]: receipts mismatch: fastdb %v, ancientdb %v, archivedb %v", num, hash, freceipts, anreceipts, areceipts)
840840
}

core/rawdb/accessors_chain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ func ReadRawReceipts(db ethdb.Reader, hash common.Hash, number uint64) types.Rec
625625
// The current implementation populates these metadata fields by reading the receipts'
626626
// corresponding block body, so if the block body is not found it will return nil even
627627
// if the receipt itself is stored.
628-
func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, config *params.ChainConfig) types.Receipts {
628+
func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, time uint64, config *params.ChainConfig) types.Receipts {
629629
// We're deriving many fields from the block body, retrieve beside the receipt
630630
receipts := ReadRawReceipts(db, hash, number)
631631
if receipts == nil {
@@ -643,7 +643,7 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, config *para
643643
} else {
644644
baseFee = header.BaseFee
645645
}
646-
if err := receipts.DeriveFields(config, hash, number, baseFee, body.Transactions); err != nil {
646+
if err := receipts.DeriveFields(config, hash, number, time, baseFee, body.Transactions); err != nil {
647647
log.Error("Failed to derive block receipts fields", "hash", hash, "number", number, "err", err)
648648
return nil
649649
}

core/rawdb/accessors_chain_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,15 @@ func TestBlockReceiptStorage(t *testing.T) {
379379

380380
// Check that no receipt entries are in a pristine database
381381
hash := common.BytesToHash([]byte{0x03, 0x14})
382-
if rs := ReadReceipts(db, hash, 0, params.TestChainConfig); len(rs) != 0 {
382+
if rs := ReadReceipts(db, hash, 0, 0, params.TestChainConfig); len(rs) != 0 {
383383
t.Fatalf("non existent receipts returned: %v", rs)
384384
}
385385
// Insert the body that corresponds to the receipts
386386
WriteBody(db, hash, 0, body)
387387

388388
// Insert the receipt slice into the database and check presence
389389
WriteReceipts(db, hash, 0, receipts)
390-
if rs := ReadReceipts(db, hash, 0, params.TestChainConfig); len(rs) == 0 {
390+
if rs := ReadReceipts(db, hash, 0, 0, params.TestChainConfig); len(rs) == 0 {
391391
t.Fatalf("no receipts returned")
392392
} else {
393393
if err := checkReceiptsRLP(rs, receipts); err != nil {
@@ -396,7 +396,7 @@ func TestBlockReceiptStorage(t *testing.T) {
396396
}
397397
// Delete the body and ensure that the receipts are no longer returned (metadata can't be recomputed)
398398
DeleteBody(db, hash, 0)
399-
if rs := ReadReceipts(db, hash, 0, params.TestChainConfig); rs != nil {
399+
if rs := ReadReceipts(db, hash, 0, 0, params.TestChainConfig); rs != nil {
400400
t.Fatalf("receipts returned when body was deleted: %v", rs)
401401
}
402402
// Ensure that receipts without metadata can be returned without the block body too
@@ -407,7 +407,7 @@ func TestBlockReceiptStorage(t *testing.T) {
407407
WriteBody(db, hash, 0, body)
408408

409409
DeleteReceipts(db, hash, 0)
410-
if rs := ReadReceipts(db, hash, 0, params.TestChainConfig); len(rs) != 0 {
410+
if rs := ReadReceipts(db, hash, 0, 0, params.TestChainConfig); len(rs) != 0 {
411411
t.Fatalf("deleted receipts returned: %v", rs)
412412
}
413413
}
@@ -727,7 +727,7 @@ func TestReadLogs(t *testing.T) {
727727

728728
hash := common.BytesToHash([]byte{0x03, 0x14})
729729
// Check that no receipt entries are in a pristine database
730-
if rs := ReadReceipts(db, hash, 0, params.TestChainConfig); len(rs) != 0 {
730+
if rs := ReadReceipts(db, hash, 0, 0, params.TestChainConfig); len(rs) != 0 {
731731
t.Fatalf("non existent receipts returned: %v", rs)
732732
}
733733
// Insert the body that corresponds to the receipts

0 commit comments

Comments
 (0)