From a77524ffe650a95287776b4c2e921b57ddc20c85 Mon Sep 17 00:00:00 2001 From: Alejandro Ranchal-Pedrosa Date: Thu, 16 Jan 2025 14:20:49 +0100 Subject: [PATCH] Finish implementation with one signer only --- consensus/system_contract/consensus.go | 8 +++++--- consensus/system_contract/system_contract.go | 11 ++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/consensus/system_contract/consensus.go b/consensus/system_contract/consensus.go index bffb2c17d1b3..bf22467f89f4 100644 --- a/consensus/system_contract/consensus.go +++ b/consensus/system_contract/consensus.go @@ -252,10 +252,13 @@ func (s *SystemContract) Seal(chain consensus.ChainHeaderReader, block *types.Bl // Don't hold the signer fields for the entire sealing procedure s.lock.RLock() signer, signFn := s.signer, s.signFn + signerAddressL1 := s.signerAddressL1 s.lock.RUnlock() // Bail out if we're unauthorized to sign a block - // todo + if signer != signerAddressL1 { + return errors.New("local node is not authorized to sign this block") + } // Sweet, the protocol permits us to sign the block, wait for our time delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple @@ -300,7 +303,6 @@ func SealHash(header *types.Header) (hash common.Hash) { return hash } - // ecrecover extracts the Ethereum account address from a signed header. func ecrecover(header *types.Header) (common.Address, error) { signature := header.Extra[0:] @@ -368,4 +370,4 @@ func encodeSigHeader(w io.Writer, header *types.Header) { if err := rlp.Encode(w, enc); err != nil { panic("can't encode: " + err.Error()) } -} \ No newline at end of file +} diff --git a/consensus/system_contract/system_contract.go b/consensus/system_contract/system_contract.go index c7919fc466af..124ab5cd87f5 100644 --- a/consensus/system_contract/system_contract.go +++ b/consensus/system_contract/system_contract.go @@ -2,7 +2,6 @@ package system_contract import ( "context" - "math/big" "sync" "time" @@ -13,7 +12,7 @@ import ( ) const ( - defaultSyncInterval = 10 + defaultSyncInterval = 10 * time.Second ) // SystemContract @@ -34,9 +33,8 @@ type SystemContract struct { // New creates a SystemContract consensus engine with the initial // signers set to the ones provided by the user. func New(ctx context.Context, config *params.SystemContractConfig, client sync_service.EthClient) *SystemContract { - blockNumber := big.NewInt(-1) // todo: get block number from L1BlocksContract (l1 block hash relay) or other source (depending on exact design) ctx, cancel := context.WithCancel(ctx) - address, err := client.StorageAt(ctx, config.SystemContractAddress, config.SystemContractSlot, blockNumber) + address, err := client.StorageAt(ctx, config.SystemContractAddress, config.SystemContractSlot, nil) if err != nil { log.Error("failed to get signer address from L1 System Contract", "err", err) } @@ -77,8 +75,7 @@ func (s *SystemContract) Start() { case <-s.ctx.Done(): return case <-syncTicker.C: - blockNumber := big.NewInt(-1) // todo: get block number from L1BlocksContract (l1 block hash relay) or other source (depending on exact design) - address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, blockNumber) + address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, nil) if err != nil { log.Error("failed to get signer address from L1 System Contract", "err", err) } @@ -94,4 +91,4 @@ func (s *SystemContract) Start() { func (s *SystemContract) Close() error { s.cancel() return nil -} \ No newline at end of file +}