Skip to content

Commit

Permalink
Merge pull request #2068 from OffchainLabs/node-interface-l3-confs
Browse files Browse the repository at this point in the history
Fix getL1Confirmations on L3s
  • Loading branch information
PlasmaPower authored Jan 10, 2024
2 parents e065123 + a211e2b commit 27d9d44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
34 changes: 30 additions & 4 deletions nodeInterface/NodeInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ import (
"math/big"
"sort"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/arbitrum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbnode"
"github.com/offchainlabs/nitro/arbos"
"github.com/offchainlabs/nitro/arbos/l1pricing"
"github.com/offchainlabs/nitro/arbos/retryables"
"github.com/offchainlabs/nitro/arbos/util"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/solgen/go/node_interfacegen"
"github.com/offchainlabs/nitro/staker"
"github.com/offchainlabs/nitro/util/arbmath"
"github.com/offchainlabs/nitro/util/merkletree"
Expand Down Expand Up @@ -94,14 +97,37 @@ func (n NodeInterface) GetL1Confirmations(c ctx, evm mech, blockHash bytes32) (u
return 0, err
}
}
latestL1Block, latestBatchCount := node.InboxReader.GetLastReadBlockAndBatchCount()
if latestBatchCount <= batch {
return 0, nil // batch was reorg'd out?
}
meta, err := node.InboxTracker.GetBatchMetadata(batch)
if err != nil {
return 0, err
}
if node.L1Reader.IsParentChainArbitrum() {
parentChainClient := node.L1Reader.Client()
parentNodeInterface, err := node_interfacegen.NewNodeInterface(types.NodeInterfaceAddress, parentChainClient)
if err != nil {
return 0, err
}
parentChainBlock, err := parentChainClient.BlockByNumber(n.context, new(big.Int).SetUint64(meta.ParentChainBlock))
if err != nil {
// Hide the parent chain RPC error from the client in case it contains sensitive information.
// Likely though, this error is just "not found" because the block got reorg'd.
return 0, fmt.Errorf("failed to get parent chain block %v containing batch", meta.ParentChainBlock)
}
confs, err := parentNodeInterface.GetL1Confirmations(&bind.CallOpts{Context: n.context}, parentChainBlock.Hash())
if err != nil {
log.Warn(
"Failed to get L1 confirmations from parent chain",
"blockNumber", meta.ParentChainBlock,
"blockHash", parentChainBlock.Hash(), "err", err,
)
return 0, fmt.Errorf("failed to get L1 confirmations from parent chain for block %v", parentChainBlock.Hash())
}
return confs, nil
}
latestL1Block, latestBatchCount := node.InboxReader.GetLastReadBlockAndBatchCount()
if latestBatchCount <= batch {
return 0, nil // batch was reorg'd out?
}
if latestL1Block < meta.ParentChainBlock || arbutil.BlockNumberToMessageCount(blockNum, genesis) > meta.MessageCount {
return 0, nil
}
Expand Down
3 changes: 3 additions & 0 deletions wsbroadcastserver/clientconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func (cc *ClientConnection) writeBacklog(ctx context.Context, segment backlog.Ba
msgs = msgs[requestedIdx:]
}
}
if len(msgs) == 0 {
break
}
isFirstSegment = false
bm := &m.BroadcastMessage{
Version: m.V1,
Expand Down

0 comments on commit 27d9d44

Please sign in to comment.