Skip to content

Commit a77524f

Browse files
committed
Finish implementation with one signer only
1 parent 8e4deb1 commit a77524f

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

consensus/system_contract/consensus.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,13 @@ func (s *SystemContract) Seal(chain consensus.ChainHeaderReader, block *types.Bl
252252
// Don't hold the signer fields for the entire sealing procedure
253253
s.lock.RLock()
254254
signer, signFn := s.signer, s.signFn
255+
signerAddressL1 := s.signerAddressL1
255256
s.lock.RUnlock()
256257

257258
// Bail out if we're unauthorized to sign a block
258-
// todo
259+
if signer != signerAddressL1 {
260+
return errors.New("local node is not authorized to sign this block")
261+
}
259262

260263
// Sweet, the protocol permits us to sign the block, wait for our time
261264
delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple
@@ -300,7 +303,6 @@ func SealHash(header *types.Header) (hash common.Hash) {
300303
return hash
301304
}
302305

303-
304306
// ecrecover extracts the Ethereum account address from a signed header.
305307
func ecrecover(header *types.Header) (common.Address, error) {
306308
signature := header.Extra[0:]
@@ -368,4 +370,4 @@ func encodeSigHeader(w io.Writer, header *types.Header) {
368370
if err := rlp.Encode(w, enc); err != nil {
369371
panic("can't encode: " + err.Error())
370372
}
371-
}
373+
}

consensus/system_contract/system_contract.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package system_contract
22

33
import (
44
"context"
5-
"math/big"
65
"sync"
76
"time"
87

@@ -13,7 +12,7 @@ import (
1312
)
1413

1514
const (
16-
defaultSyncInterval = 10
15+
defaultSyncInterval = 10 * time.Second
1716
)
1817

1918
// SystemContract
@@ -34,9 +33,8 @@ type SystemContract struct {
3433
// New creates a SystemContract consensus engine with the initial
3534
// signers set to the ones provided by the user.
3635
func New(ctx context.Context, config *params.SystemContractConfig, client sync_service.EthClient) *SystemContract {
37-
blockNumber := big.NewInt(-1) // todo: get block number from L1BlocksContract (l1 block hash relay) or other source (depending on exact design)
3836
ctx, cancel := context.WithCancel(ctx)
39-
address, err := client.StorageAt(ctx, config.SystemContractAddress, config.SystemContractSlot, blockNumber)
37+
address, err := client.StorageAt(ctx, config.SystemContractAddress, config.SystemContractSlot, nil)
4038
if err != nil {
4139
log.Error("failed to get signer address from L1 System Contract", "err", err)
4240
}
@@ -77,8 +75,7 @@ func (s *SystemContract) Start() {
7775
case <-s.ctx.Done():
7876
return
7977
case <-syncTicker.C:
80-
blockNumber := big.NewInt(-1) // todo: get block number from L1BlocksContract (l1 block hash relay) or other source (depending on exact design)
81-
address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, blockNumber)
78+
address, err := s.client.StorageAt(s.ctx, s.config.SystemContractAddress, s.config.SystemContractSlot, nil)
8279
if err != nil {
8380
log.Error("failed to get signer address from L1 System Contract", "err", err)
8481
}
@@ -94,4 +91,4 @@ func (s *SystemContract) Start() {
9491
func (s *SystemContract) Close() error {
9592
s.cancel()
9693
return nil
97-
}
94+
}

0 commit comments

Comments
 (0)