Skip to content

Commit b2d6f07

Browse files
Merge pull request #73 from mdehoog/time-based-forking
Time based forking
2 parents 01d1f49 + dac0e11 commit b2d6f07

Some content is hidden

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

52 files changed

+168
-131
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
672672
return fmt.Errorf("could not fetch parent")
673673
}
674674
// Check transaction validity
675-
signer := types.MakeSigner(b.blockchain.Config(), block.Number())
675+
signer := types.MakeSigner(b.blockchain.Config(), block.Number(), block.Time())
676676
sender, err := types.Sender(signer, tx)
677677
if err != nil {
678678
return fmt.Errorf("invalid transaction: %v", err)

cmd/evm/internal/t8ntool/execution.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
123123
}
124124
var (
125125
statedb = MakePreState(rawdb.NewMemoryDatabase(), pre.Pre)
126-
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number))
126+
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
127127
gaspool = new(core.GasPool)
128128
blockHash = common.Hash{0x13, 0x37}
129129
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
@@ -241,7 +241,7 @@ func Transition(ctx *cli.Context) error {
241241
}
242242
}
243243
// We may have to sign the transactions.
244-
signer := types.MakeSigner(chainConfig, big.NewInt(int64(prestate.Env.Number)))
244+
signer := types.MakeSigner(chainConfig, big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp)
245245

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

consensus/beacon/consensus.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
269269
return err
270270
}
271271
}
272-
shanghai := chain.Config().IsShanghai(header.Number)
272+
shanghai := chain.Config().IsShanghai(header.Time)
273273
if shanghai && header.WithdrawalsHash == nil {
274274
return fmt.Errorf("missing withdrawalsHash")
275275
}
276276
// Verify existence / non-existence of withdrawalsHash.
277277
if !shanghai && header.WithdrawalsHash != nil {
278278
return fmt.Errorf("invalid withdrawalsHash: have %s, expected nil", header.WithdrawalsHash)
279279
}
280-
if chain.Config().IsSharding(header.Number) {
280+
if chain.Config().IsSharding(header.Time) {
281281
// Verify the header's EIP-4844 attributes.
282282
if err := misc.VerifyEip4844Header(chain.Config(), parent, header); err != nil {
283283
return err
@@ -350,15 +350,15 @@ func (beacon *Beacon) Finalize(chain consensus.ChainHeaderReader, header *types.
350350
return
351351
}
352352
// If withdrawals have been activated, process each one.
353-
if chain.Config().IsShanghai(header.Number) {
353+
if chain.Config().IsShanghai(header.Time) {
354354
for _, w := range withdrawals {
355355
state.AddBalance(w.Address, w.Amount)
356356
}
357357
}
358358
// The block reward is no longer handled here. It's done by the
359359
// external consensus engine.
360360
header.Root = state.IntermediateRoot(true)
361-
if chain.Config().IsSharding(header.Number) {
361+
if chain.Config().IsSharding(header.Time) {
362362
if parent := chain.GetHeaderByHash(header.ParentHash); parent != nil {
363363
header.SetExcessDataGas(misc.CalcExcessDataGas(parent.ExcessDataGas, misc.CountBlobs(txs)))
364364
} else {

consensus/clique/clique.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
345345
// Verify the header's EIP-1559 attributes.
346346
return err
347347
}
348-
if !chain.Config().IsSharding(header.Number) {
348+
if !chain.Config().IsSharding(header.Time) {
349349
if header.ExcessDataGas != nil {
350350
return fmt.Errorf("invalid excessDataGas before fork: have %v, want <nil>", header.ExcessDataGas)
351351
}
@@ -576,7 +576,7 @@ func (c *Clique) Finalize(chain consensus.ChainHeaderReader, header *types.Heade
576576
// No block rewards in PoA, so the state remains as is and uncles are dropped
577577
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
578578
header.UncleHash = types.CalcUncleHash(nil)
579-
if chain.Config().IsSharding(header.Number) {
579+
if chain.Config().IsSharding(header.Time) {
580580
if parent := chain.GetHeaderByHash(header.ParentHash); parent != nil {
581581
header.SetExcessDataGas(misc.CalcExcessDataGas(parent.ExcessDataGas, misc.CountBlobs(txs)))
582582
} else {

consensus/ethash/consensus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
306306
// Verify the header's EIP-1559 attributes.
307307
return err
308308
}
309-
if !chain.Config().IsSharding(header.Number) {
309+
if !chain.Config().IsSharding(header.Time) {
310310
if header.ExcessDataGas != nil {
311311
return fmt.Errorf("invalid excessDataGas before fork: have %v, expected 'nil'", header.ExcessDataGas)
312312
}
@@ -609,7 +609,7 @@ func (ethash *Ethash) Finalize(chain consensus.ChainHeaderReader, header *types.
609609
// Accumulate any block and uncle rewards and commit the final state root
610610
accumulateRewards(chain.Config(), state, header, uncles)
611611
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
612-
if chain.Config().IsSharding(header.Number) {
612+
if chain.Config().IsSharding(header.Time) {
613613
if parent := chain.GetHeaderByHash(header.ParentHash); parent != nil {
614614
header.SetExcessDataGas(misc.CalcExcessDataGas(parent.ExcessDataGas, misc.CountBlobs(txs)))
615615
} else {

core/bench_test.go

Lines changed: 2 additions & 2 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)
87-
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)))
87+
signer := types.MakeSigner(gen.config, big.NewInt(int64(i)), 0)
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)), 0)
132132
for {
133133
gas -= params.TxGas
134134
if gas < params.TxGas {

core/blockchain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
14881488
}
14891489

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

14931493
var (
14941494
stats = insertStats{startTime: mclock.Now()}

core/blockchain_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4138,7 +4138,8 @@ func TestDataBlobTxs(t *testing.T) {
41384138
// Genesis (block 0): AllEthhashProtocolChanges
41394139
// Block 1 : ""
41404140
// Block 2 : Sharding
4141-
gspec.Config.ShardingForkBlock = common.Big2
4141+
var time uint64 = 2 * 10 // block time is 10 seconds, so this corresponds to second block.
4142+
gspec.Config.ShardingForkTime = &time
41424143
genesis := gspec.MustCommit(db)
41434144
signer := types.LatestSigner(gspec.Config)
41444145

@@ -4158,7 +4159,7 @@ func TestDataBlobTxs(t *testing.T) {
41584159
msg.GasFeeCap.SetFromBig(newGwei(5))
41594160
msg.GasTipCap.SetFromBig(big.NewInt(2))
41604161
msg.MaxFeePerDataGas.SetFromBig(big.NewInt(params.MinDataGasPrice))
4161-
// TODO: Add test case for max data fee too low
4162+
// TODO(eip-4844): Add test case for max data fee too low
41624163
msg.BlobVersionedHashes = []common.Hash{one, two}
41634164
txdata := &types.SignedBlobTx{Message: msg}
41644165

@@ -4332,7 +4333,7 @@ func TestEIP3651(t *testing.T) {
43324333

43334334
gspec.Config.BerlinBlock = common.Big0
43344335
gspec.Config.LondonBlock = common.Big0
4335-
gspec.Config.ShanghaiBlock = common.Big0
4336+
gspec.Config.ShanghaiTime = new(uint64)
43364337
signer := types.LatestSigner(gspec.Config)
43374338

43384339
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) {

0 commit comments

Comments
 (0)