Skip to content

Commit

Permalink
Finish implementation with one signer only
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchalp committed Jan 16, 2025
1 parent 8e4deb1 commit a77524f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 5 additions & 3 deletions consensus/system_contract/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:]
Expand Down Expand Up @@ -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())
}
}
}
11 changes: 4 additions & 7 deletions consensus/system_contract/system_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package system_contract

import (
"context"
"math/big"
"sync"
"time"

Expand All @@ -13,7 +12,7 @@ import (
)

const (
defaultSyncInterval = 10
defaultSyncInterval = 10 * time.Second
)

// SystemContract
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -94,4 +91,4 @@ func (s *SystemContract) Start() {
func (s *SystemContract) Close() error {
s.cancel()
return nil
}
}

0 comments on commit a77524f

Please sign in to comment.