Commit cb4a928b authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

fix: deterministic blockhashes (#1032)

* config: set etherbase

* l2geth: add deterministic clique key

* l2geth: default value

* chore: add changeset

* test: add sync test for deterministic blockhash
Co-authored-by: default avatarKevin Ho <kevinjho1996@gmail.com>
parent a75f05b7
---
'@eth-optimism/l2geth': patch
---
Make block hashes deterministic by using the same clique signer key
...@@ -60,7 +60,7 @@ describe('Syncing a verifier', () => { ...@@ -60,7 +60,7 @@ describe('Syncing a verifier', () => {
}) })
describe('Basic transactions', () => { describe('Basic transactions', () => {
afterEach(async () => { after(async () => {
await verifier.stop('verifier') await verifier.stop('verifier')
await verifier.rm() await verifier.rm()
}) })
...@@ -97,5 +97,13 @@ describe('Syncing a verifier', () => { ...@@ -97,5 +97,13 @@ describe('Syncing a verifier', () => {
latestSequencerBlock.stateRoot latestSequencerBlock.stateRoot
) )
}) })
it('should have matching block data', async () => {
const sequencerTip = await sequencerProvider.getBlock('latest')
const verifierTip = await provider.getBlock('latest')
expect(sequencerTip.number).to.deep.eq(verifierTip.number)
expect(sequencerTip.hash).to.deep.eq(verifierTip.hash)
})
}) })
}) })
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package keystore package keystore
import ( import (
"bytes"
"crypto/ecdsa" "crypto/ecdsa"
crand "crypto/rand" crand "crypto/rand"
"errors" "errors"
...@@ -36,8 +37,10 @@ import ( ...@@ -36,8 +37,10 @@ import (
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
) )
var ( var (
...@@ -80,6 +83,21 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore { ...@@ -80,6 +83,21 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
keydir, _ = filepath.Abs(keydir) keydir, _ = filepath.Abs(keydir)
ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}} ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}}
ks.init(keydir) ks.init(keydir)
if vm.UsingOVM {
// Add a deterministic key to the key store so that
// all clique blocks are signed with the same key
input := make([]byte, 65)
rng := bytes.NewReader(input)
key, err := newKey(rng)
log.Info("Adding key to keyring", "address", key.Address.Hex())
if err != nil {
panic(fmt.Sprintf("cannot create key: %s", err))
}
_, err = ks.importKey(key, "")
if err != nil {
panic(fmt.Sprintf("cannot import key: %s", err))
}
}
return ks return ks
} }
......
...@@ -471,12 +471,13 @@ var ( ...@@ -471,12 +471,13 @@ var (
MinerEtherbaseFlag = cli.StringFlag{ MinerEtherbaseFlag = cli.StringFlag{
Name: "miner.etherbase", Name: "miner.etherbase",
Usage: "Public address for block mining rewards (default = first account)", Usage: "Public address for block mining rewards (default = first account)",
Value: "0",
Value: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
EnvVar: "ETHERBASE",
} }
MinerLegacyEtherbaseFlag = cli.StringFlag{ MinerLegacyEtherbaseFlag = cli.StringFlag{
Name: "etherbase", Name: "etherbase",
Usage: "Public address for block mining rewards (default = first account, deprecated, use --miner.etherbase)", Usage: "Public address for block mining rewards (default = first account, deprecated, use --miner.etherbase)",
Value: "0",
} }
MinerExtraDataFlag = cli.StringFlag{ MinerExtraDataFlag = cli.StringFlag{
Name: "miner.extradata", Name: "miner.extradata",
......
...@@ -23,7 +23,6 @@ import ( ...@@ -23,7 +23,6 @@ import (
"io" "io"
"math/big" "math/big"
"math/rand" "math/rand"
"os"
"sync" "sync"
"time" "time"
...@@ -34,6 +33,7 @@ import ( ...@@ -34,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header, ...@@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
} }
number := header.Number.Uint64() number := header.Number.Uint64()
if os.Getenv("USING_OVM") != "true" { if vm.UsingOVM {
// Don't waste time checking blocks from the future // Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().Unix()) { if header.Time > uint64(time.Now().Unix()) {
return consensus.ErrFutureBlock return consensus.ErrFutureBlock
...@@ -631,7 +631,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c ...@@ -631,7 +631,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle)) log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
} }
if os.Getenv("USING_OVM") == "true" { if vm.UsingOVM {
delay = 0 delay = 0
} }
// Sign all the things! // Sign all the things!
......
...@@ -9,6 +9,8 @@ ROLLUP_POLL_INTERVAL_FLAG=500ms ...@@ -9,6 +9,8 @@ ROLLUP_POLL_INTERVAL_FLAG=500ms
ROLLUP_ENABLE_L2_GAS_POLLING=true ROLLUP_ENABLE_L2_GAS_POLLING=true
# ROLLUP_ENFORCE_FEES= # ROLLUP_ENFORCE_FEES=
ETHERBASE=0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
RPC_ENABLE=true RPC_ENABLE=true
RPC_ADDR=0.0.0.0 RPC_ADDR=0.0.0.0
RPC_PORT=8545 RPC_PORT=8545
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment