Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func newBridgeState(
var BridgeStateEmpty = newBridgeState(common.EmptyHash, common.EmptyHash, big.NewInt(0))

type BridgeStateGetter interface {
GetBridgeState(ctx context.Context, blockHash common.Hash) (*BridgeState, error)
GetBridgeState(
ctx context.Context, execShardBlockHash common.Hash, mainShardBlockHash common.Hash,
) (*BridgeState, error)
}

type bridgeStateGetter struct {
Expand All @@ -61,14 +63,16 @@ func NewBridgeStateGetter(
}
}

func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common.Hash) (*BridgeState, error) {
exists, err := b.contactExistsAtBlock(ctx, blockHash)
func (b *bridgeStateGetter) GetBridgeState(
ctx context.Context, execShardBlockHash common.Hash, mainShardBlockHash common.Hash,
) (*BridgeState, error) {
exists, err := b.contactExistsAtBlock(ctx, execShardBlockHash)
if err != nil {
return nil, err
}
if !exists {
b.logger.Warn().
Any(logging.FieldBlockHash, blockHash).
Any(logging.FieldBlockHash, execShardBlockHash).
Msg("L2 bridge contract does not exist at specified block, empty state will be returned")
return &BridgeStateEmpty, nil
}
Expand All @@ -78,9 +82,9 @@ func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common
var l1MessageHash common.Hash
eg.Go(func() error {
const method = "l1MessageHash"
ret, err := callContract[bytes32](gCtx, b.nilClient, blockHash, b.contractAddr, b.abi, method)
ret, err := callContract[bytes32](gCtx, b.nilClient, mainShardBlockHash, b.contractAddr, b.abi, method)
if err != nil {
return b.callError(method, blockHash, err)
return b.callError(method, mainShardBlockHash, err)
}
l1MessageHash = common.BytesToHash(ret[:])
return nil
Expand All @@ -89,9 +93,9 @@ func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common
var l2ToL1Root common.Hash
eg.Go(func() error {
const method = "getL2ToL1Root"
ret, err := callContract[bytes32](gCtx, b.nilClient, blockHash, b.contractAddr, b.abi, method)
ret, err := callContract[bytes32](gCtx, b.nilClient, mainShardBlockHash, b.contractAddr, b.abi, method)
if err != nil {
return b.callError(method, blockHash, err)
return b.callError(method, mainShardBlockHash, err)
}
l2ToL1Root = common.BytesToHash(ret[:])
return nil
Expand All @@ -100,9 +104,9 @@ func (b *bridgeStateGetter) GetBridgeState(ctx context.Context, blockHash common
var depositNonce *big.Int
eg.Go(func() error {
const method = "getLatestDepositNonce"
ret, err := callContract[*big.Int](gCtx, b.nilClient, blockHash, b.contractAddr, b.abi, method)
ret, err := callContract[*big.Int](gCtx, b.nilClient, mainShardBlockHash, b.contractAddr, b.abi, method)
if err != nil {
return b.callError(method, blockHash, err)
return b.callError(method, mainShardBlockHash, err)
}
depositNonce = ret
return nil
Expand Down
4 changes: 3 additions & 1 deletion nil/services/synccommittee/core/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ func (p *proposer) updateState(
return fmt.Errorf("failed to get latest block for shard %d", p.config.BridgeStateKeeperShardId)
}

bridgeData, err := p.bridgeStateGetter.GetBridgeState(ctx, bridgeContractShardBlock.MainShardHash)
bridgeData, err := p.bridgeStateGetter.GetBridgeState(
ctx, bridgeContractShardBlock.Hash, bridgeContractShardBlock.MainShardHash,
)
if err != nil {
return fmt.Errorf("failed to get bridge state: %w", err)
}
Expand Down