Skip to content

Commit e2dd991

Browse files
authored
Merge pull request #984 from NilFoundation/sync-committee/fix-get-bridge-state
Sync Committee: BridgeStateGetter Fix
2 parents 2e9ee8c + 4ffe886 commit e2dd991

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

nil/services/synccommittee/core/bridgecontract/bridge_state_getter.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ func newBridgeState(
3838
var BridgeStateEmpty = newBridgeState(common.EmptyHash, common.EmptyHash, big.NewInt(0))
3939

4040
type BridgeStateGetter interface {
41-
GetBridgeState(ctx context.Context, blockHash common.Hash) (*BridgeState, error)
41+
GetBridgeState(
42+
ctx context.Context, execShardBlockHash common.Hash, mainShardBlockHash common.Hash,
43+
) (*BridgeState, error)
4244
}
4345

4446
type bridgeStateGetter struct {
@@ -61,14 +63,16 @@ func NewBridgeStateGetter(
6163
}
6264
}
6365

64-
func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common.Hash) (*BridgeState, error) {
65-
exists, err := b.contactExistsAtBlock(ctx, blockHash)
66+
func (b *bridgeStateGetter) GetBridgeState(
67+
ctx context.Context, execShardBlockHash common.Hash, mainShardBlockHash common.Hash,
68+
) (*BridgeState, error) {
69+
exists, err := b.contactExistsAtBlock(ctx, execShardBlockHash)
6670
if err != nil {
6771
return nil, err
6872
}
6973
if !exists {
7074
b.logger.Warn().
71-
Any(logging.FieldBlockHash, blockHash).
75+
Any(logging.FieldBlockHash, execShardBlockHash).
7276
Msg("L2 bridge contract does not exist at specified block, empty state will be returned")
7377
return &BridgeStateEmpty, nil
7478
}
@@ -78,9 +82,9 @@ func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common
7882
var l1MessageHash common.Hash
7983
eg.Go(func() error {
8084
const method = "l1MessageHash"
81-
ret, err := callContract[bytes32](gCtx, b.nilClient, blockHash, b.contractAddr, b.abi, method)
85+
ret, err := callContract[bytes32](gCtx, b.nilClient, mainShardBlockHash, b.contractAddr, b.abi, method)
8286
if err != nil {
83-
return b.callError(method, blockHash, err)
87+
return b.callError(method, mainShardBlockHash, err)
8488
}
8589
l1MessageHash = common.BytesToHash(ret[:])
8690
return nil
@@ -89,9 +93,9 @@ func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common
8993
var l2ToL1Root common.Hash
9094
eg.Go(func() error {
9195
const method = "getL2ToL1Root"
92-
ret, err := callContract[bytes32](gCtx, b.nilClient, blockHash, b.contractAddr, b.abi, method)
96+
ret, err := callContract[bytes32](gCtx, b.nilClient, mainShardBlockHash, b.contractAddr, b.abi, method)
9397
if err != nil {
94-
return b.callError(method, blockHash, err)
98+
return b.callError(method, mainShardBlockHash, err)
9599
}
96100
l2ToL1Root = common.BytesToHash(ret[:])
97101
return nil
@@ -100,9 +104,9 @@ func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common
100104
var depositNonce *big.Int
101105
eg.Go(func() error {
102106
const method = "getLatestDepositNonce"
103-
ret, err := callContract[*big.Int](gCtx, b.nilClient, blockHash, b.contractAddr, b.abi, method)
107+
ret, err := callContract[*big.Int](gCtx, b.nilClient, mainShardBlockHash, b.contractAddr, b.abi, method)
104108
if err != nil {
105-
return b.callError(method, blockHash, err)
109+
return b.callError(method, mainShardBlockHash, err)
106110
}
107111
depositNonce = ret
108112
return nil

nil/services/synccommittee/core/proposer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ func (p *proposer) updateState(
131131
return fmt.Errorf("failed to get latest block for shard %d", p.config.BridgeStateKeeperShardId)
132132
}
133133

134-
bridgeData, err := p.bridgeStateGetter.GetBridgeState(ctx, bridgeContractShardBlock.MainShardHash)
134+
bridgeData, err := p.bridgeStateGetter.GetBridgeState(
135+
ctx, bridgeContractShardBlock.Hash, bridgeContractShardBlock.MainShardHash,
136+
)
135137
if err != nil {
136138
return fmt.Errorf("failed to get bridge state: %w", err)
137139
}

0 commit comments

Comments
 (0)