@@ -2,6 +2,7 @@ package system_contract
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"sync"
6
7
"time"
7
8
@@ -34,19 +35,19 @@ type SystemContract struct {
34
35
// signers set to the ones provided by the user.
35
36
func New (ctx context.Context , config * params.SystemContractConfig , client sync_service.EthClient ) * SystemContract {
36
37
ctx , cancel := context .WithCancel (ctx )
37
- address , err := client .StorageAt (ctx , config .SystemContractAddress , config .SystemContractSlot , nil )
38
- if err != nil {
39
- log .Error ("failed to get signer address from L1 System Contract" , "err" , err )
40
- }
41
38
42
- return & SystemContract {
43
- config : config ,
44
- client : client ,
45
- signerAddressL1 : common .BytesToAddress (address ),
39
+ s := & SystemContract {
40
+ config : config ,
41
+ client : client ,
46
42
47
43
ctx : ctx ,
48
44
cancel : cancel ,
49
45
}
46
+
47
+ if err := s .fetchAddressFromL1 (); err != nil {
48
+ log .Error ("failed to fetch signer address from L1" , "err" , err )
49
+ }
50
+ return s
50
51
}
51
52
52
53
// Authorize injects a private key into the consensus engine to mint new blocks
@@ -75,20 +76,27 @@ func (s *SystemContract) Start() {
75
76
case <- s .ctx .Done ():
76
77
return
77
78
case <- syncTicker .C :
78
- s .fetchAddressFromL1 ()
79
+ if err := s .fetchAddressFromL1 (); err != nil {
80
+ log .Error ("failed to fetch signer address from L1" , "err" , err )
81
+ }
79
82
}
80
83
}
81
84
}()
82
85
}
83
86
84
- func (s * SystemContract ) fetchAddressFromL1 () {
87
+ func (s * SystemContract ) fetchAddressFromL1 () error {
85
88
address , err := s .client .StorageAt (s .ctx , s .config .SystemContractAddress , s .config .SystemContractSlot , nil )
86
89
if err != nil {
87
- log . Error ("failed to get signer address from L1 System Contract" , "err " , err )
90
+ return fmt . Errorf ("failed to get signer address from L1 System Contract: %w " , err )
88
91
}
89
92
bAddress := common .BytesToAddress (address )
90
93
91
- log .Info ("Read address from system contract" , "address" , bAddress .Hex ())
94
+ // Validate the address is not empty
95
+ if bAddress == (common.Address {}) {
96
+ return fmt .Errorf ("retrieved empty signer address from L1 System Contract" )
97
+ }
98
+
99
+ log .Debug ("Read address from system contract" , "address" , bAddress .Hex ())
92
100
93
101
s .lock .RLock ()
94
102
addressChanged := s .signerAddressL1 != bAddress
@@ -99,6 +107,8 @@ func (s *SystemContract) fetchAddressFromL1() {
99
107
s .signerAddressL1 = bAddress
100
108
s .lock .Unlock ()
101
109
}
110
+
111
+ return nil
102
112
}
103
113
104
114
// Close implements consensus.Engine.
0 commit comments