Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonShiesty committed Oct 31, 2023
1 parent 7252884 commit adf81e3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 16 deletions.
5 changes: 5 additions & 0 deletions contracts/src/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ interface IRollup {
*/
function currentRequiredStake() external view returns (uint256);

/**
* @return confirmedBlockNum size of inbox confirmed
*/
function confirmedBlockNum() external view returns (uint256);

/**
* @notice Requires that the first unresolved assertion is confirmable. Otherwise, reverts.
* This is exposed as a utility function to validators.
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ interface ISequencerInbox is IDAProvider {
/// @dev Thrown when sequencer tries to append an empty batch
error EmptyBatch();

/// @dev Thrown when underflow occurs reading txBatch
/// @dev Thrown when underflow occurs reading txBatchData
error TxBatchDataUnderflow();

/// @dev Thrown when overflow occurs reading txBatch
/// @dev Thrown when overflow occurs reading txBatchData
error TxBatchDataOverflow();

/// @dev Thrown when a transaction batch has an incorrect version
Expand Down
5 changes: 5 additions & 0 deletions contracts/src/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ contract Rollup is RollupBase {
return baseStakeAmount;
}

/// @inheritdoc IRollup
function confirmedBlockNum() public view override returns (uint256) {
return assertions[lastConfirmedAssertionID].blockNum;
}

/// @inheritdoc IRollup
function getStaker(address addr) external view override returns (Staker memory) {
return stakers[addr];
Expand Down
5 changes: 3 additions & 2 deletions contracts/test/SequencerInbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ contract SequencerInboxTest is SequencerBaseSetup {
seqIn.appendTxBatch(hex"00");
}

function test_appendTxBatch_emptyBatch_succeeds() public {
function test_appendTxBatch_invalidVersion_reverts() public {
vm.expectRevert(ISequencerInbox.TxBatchVersionIncorrect.selector);
vm.prank(sequencerAddress);
seqIn.appendTxBatch(hex"00");
seqIn.appendTxBatch(hex"01"); // version 0 is the only valid version
}

//////////////////////////////
Expand Down
13 changes: 9 additions & 4 deletions services/sidecar/rollup/derivation/batch_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package derivation

import (
"bytes"
"errors"
"fmt"
"io"
"math/big"
Expand All @@ -16,7 +17,7 @@ type batchBuilder struct {
maxBatchSize uint64

pendingBlocks []DerivationBlock
builtBatchData *[]byte
builtBatchData []byte

lastAppended types.BlockID
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func (b *batchBuilder) Reset(lastAppended types.BlockID) {

// This short-circuits the build process if a batch is
// already built and `Advance` hasn't been called.
func (b *batchBuilder) Build() (*[]byte, error) {
func (b *batchBuilder) Build() ([]byte, error) {
if b.builtBatchData != nil {
return b.builtBatchData, nil
}
Expand All @@ -86,7 +87,7 @@ func (b *batchBuilder) Build() (*[]byte, error) {
return nil, fmt.Errorf("failed to encode batch: %w", err)
}

b.builtBatchData = &batchData
b.builtBatchData = batchData
return b.builtBatchData, nil
}

Expand All @@ -95,6 +96,10 @@ func (b *batchBuilder) Advance() {
}

func (b *batchBuilder) serializeToAttrs() (*BatchAttributes, error) {
if len(b.pendingBlocks) == 0 {
return nil, errors.New("no pending blocks")
}

var (
block DerivationBlock
idx int
Expand Down Expand Up @@ -122,7 +127,7 @@ func (b *batchBuilder) serializeToAttrs() (*BatchAttributes, error) {
}
// Construct batch attributes.
attrs := &BatchAttributes{firstL2BlockNumber, blocks}
log.Info("Serialized l2 blocks", "first", firstL2BlockNumber, "last", b.pendingBlocks[idx].BlockNumber())
log.Info("Serialized l2 blocks", "first", firstL2BlockNumber, "last", block.BlockNumber())
// Advance queue.
b.pendingBlocks = b.pendingBlocks[idx+1:]
log.Trace("Advanced pending blocks", "len", len(b.pendingBlocks))
Expand Down
11 changes: 8 additions & 3 deletions services/sidecar/rollup/derivation/derivation_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ func BlocksFromData(calldata []any) ([]DerivationBlock, error) {
}

txBatchVersion := txBatchData[0]
if txBatchVersion != TxBatchVersion() {
return nil, &DecodeTxBatchError{fmt.Sprintf("invalid tx batch version")}
switch txBatchVersion {
case 0:
return blocksFromV0Data(txBatchData[1:])
default:
return nil, &DecodeTxBatchError{fmt.Sprintf("invalid tx batch version: {%d}", txBatchVersion)}
}
}

func blocksFromV0Data(v0Data []byte) ([]DerivationBlock, error) {
var decodedBatch BatchAttributes
if err := rlp.Decode(bytes.NewReader(txBatchData[:1]), &decodedBatch); err != nil {
if err := rlp.Decode(bytes.NewReader(v0Data), &decodedBatch); err != nil {
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion services/sidecar/rollup/rpc/bridge/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func UnpackAppendTxBatchInput(tx *types.Transaction) ([]any, error) {
return serializationUtil.inboxAbi.Methods[AppendTxBatchFnName].Inputs.Unpack(tx.Data()[MethodNumBytes:])
}

func packAppendTxBatchInput(txBatchData *[]byte) ([]byte, error) {
func packAppendTxBatchInput(txBatchData []byte) ([]byte, error) {
return serializationUtil.inboxAbi.Pack(AppendTxBatchFnName, txBatchData)
}

Expand Down
4 changes: 2 additions & 2 deletions services/sidecar/rollup/rpc/bridge/tx_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func NewTxManager(txMgr EthTxManager, cfg bridgeConfig) (*TxManager, error) {

func (m *TxManager) AppendTxBatch(
ctx context.Context,
txBatch *[]byte,
txBatchData []byte,
) (*types.Receipt, error) {
data, err := packAppendTxBatchInput(txBatch)
data, err := packAppendTxBatchInput(txBatchData)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions services/sidecar/rollup/services/disseminator/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ type BuildPayloadResponse = engine.ForkChoiceResponse
type BatchBuilder interface {
Append(block derivation.DerivationBlock, header derivation.HeaderRef) error
LastAppended() types.BlockID
Build() (*[]byte, error)
Build() ([]byte, error)
Advance()
Reset(lastAppended types.BlockID)
}

type TxManager interface {
AppendTxBatch(
ctx context.Context,
batchData *[]byte,
txBatchData []byte,
) (*ethTypes.Receipt, error)
}

Expand Down

0 comments on commit adf81e3

Please sign in to comment.