Skip to content

Commit 24d7a06

Browse files
Refactor: Use global chainID instead of Aggregator reference in RpcServer
Co-Authored-By: Chris Li <chris.li.2046@gmail.com>
1 parent a842d9b commit 24d7a06

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

aggregator/aggregator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ func (agg *Aggregator) init() {
226226
panic(err)
227227
}
228228

229+
SetGlobalChainID(agg.chainID)
230+
229231
if agg.chainID.Cmp(config.MainnetChainID) == 0 {
230232
config.CurrentChainEnv = config.EthereumEnv
231233
} else {

aggregator/auth.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,8 @@ func (r *RpcServer) GetSignatureFormat(ctx context.Context, req interface{}) (in
205205
return nil, status.Errorf(codes.InvalidArgument, "Invalid Ethereum wallet address format")
206206
}
207207

208-
var chainId *big.Int
209-
if r.agg != nil && r.agg.chainID != nil {
210-
chainId = r.agg.chainID
211-
} else {
208+
chainId := GetGlobalChainID()
209+
if chainId == nil {
212210
return nil, status.Errorf(codes.Internal, "Chain ID not available. Aggregator not fully initialized.")
213211
}
214212

aggregator/chain_id.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package aggregator
2+
3+
import (
4+
"math/big"
5+
"sync"
6+
)
7+
8+
var (
9+
globalChainID *big.Int
10+
globalChainIDLock sync.RWMutex
11+
)
12+
13+
func SetGlobalChainID(chainID *big.Int) {
14+
globalChainIDLock.Lock()
15+
defer globalChainIDLock.Unlock()
16+
globalChainID = chainID
17+
}
18+
19+
func GetGlobalChainID() *big.Int {
20+
globalChainIDLock.RLock()
21+
defer globalChainIDLock.RUnlock()
22+
return globalChainID
23+
}

aggregator/rpc_server.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ type RpcServer struct {
4141
ethrpc *ethclient.Client
4242

4343
smartWalletRpc *ethclient.Client
44-
45-
agg *Aggregator
4644
}
4745

4846
// Get nonce of an existing smart wallet of a given owner
@@ -409,8 +407,6 @@ func (agg *Aggregator) startRpcServer(ctx context.Context) error {
409407

410408
config: agg.config,
411409
operatorPool: agg.operatorPool,
412-
413-
agg: agg,
414410
}
415411

416412
// TODO: split node and aggregator

0 commit comments

Comments
 (0)