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', () => {
})
describe('Basic transactions', () => {
afterEach(async () => {
after(async () => {
await verifier.stop('verifier')
await verifier.rm()
})
......@@ -97,5 +97,13 @@ describe('Syncing a verifier', () => {
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 @@
package keystore
import (
"bytes"
"crypto/ecdsa"
crand "crypto/rand"
"errors"
......@@ -36,8 +37,10 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"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/event"
"github.com/ethereum/go-ethereum/log"
)
var (
......@@ -80,6 +83,21 @@ func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
keydir, _ = filepath.Abs(keydir)
ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}}
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
}
......
......@@ -471,12 +471,13 @@ var (
MinerEtherbaseFlag = cli.StringFlag{
Name: "miner.etherbase",
Usage: "Public address for block mining rewards (default = first account)",
Value: "0",
Value: "0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf",
EnvVar: "ETHERBASE",
}
MinerLegacyEtherbaseFlag = cli.StringFlag{
Name: "etherbase",
Usage: "Public address for block mining rewards (default = first account, deprecated, use --miner.etherbase)",
Value: "0",
}
MinerExtraDataFlag = cli.StringFlag{
Name: "miner.extradata",
......
......@@ -23,7 +23,6 @@ import (
"io"
"math/big"
"math/rand"
"os"
"sync"
"time"
......@@ -34,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/state"
"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/ethdb"
"github.com/ethereum/go-ethereum/log"
......@@ -249,7 +249,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
}
number := header.Number.Uint64()
if os.Getenv("USING_OVM") != "true" {
if vm.UsingOVM {
// Don't waste time checking blocks from the future
if header.Time > uint64(time.Now().Unix()) {
return consensus.ErrFutureBlock
......@@ -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))
}
if os.Getenv("USING_OVM") == "true" {
if vm.UsingOVM {
delay = 0
}
// Sign all the things!
......
......@@ -9,6 +9,8 @@ ROLLUP_POLL_INTERVAL_FLAG=500ms
ROLLUP_ENABLE_L2_GAS_POLLING=true
# ROLLUP_ENFORCE_FEES=
ETHERBASE=0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
RPC_ENABLE=true
RPC_ADDR=0.0.0.0
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