Skip to content

Commit

Permalink
Merge pull request #1815 from ten-protocol/willh/enclave-api-get-batc…
Browse files Browse the repository at this point in the history
…h-start-seq

Add new GetRollupData API to enclave client
  • Loading branch information
badgersrus authored Feb 28, 2024
2 parents b17c332 + a4e9557 commit a231667
Show file tree
Hide file tree
Showing 14 changed files with 1,487 additions and 1,079 deletions.
5 changes: 4 additions & 1 deletion go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ type Enclave interface {
// GetBatch - retrieve a batch if existing within the enclave db.
GetBatch(hash L2BatchHash) (*ExtBatch, SystemError)

// GetBatchBySeqNo - retrieve batch by sequencer number if it's in the db
// GetBatchBySeqNo - retrieve batch by sequencer number if it's in the db.
GetBatchBySeqNo(seqNo uint64) (*ExtBatch, SystemError)

// GetRollupData - retrieve the first batch sequence and start time for a given rollup.
GetRollupData(hash L2RollupHash) (*PublicRollupMetadata, SystemError)

// CreateBatch - creates a new head batch extending the previous one for the latest known L1 head if the node is
// a sequencer. Will panic otherwise.
CreateBatch(skipIfEmpty bool) SystemError
Expand Down
6 changes: 6 additions & 0 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ type CalldataRollupHeader struct {
ReOrgs [][]byte `rlp:"optional"` // sparse list of reorged headers - non null only for reorgs.
}

// PublicRollupMetadata contains internal rollup data that can be requested from the enclave.
type PublicRollupMetadata struct {
FirstBatchSequence *big.Int
StartTime uint64
}

// MarshalJSON custom marshals the RollupHeader into a json
func (r *RollupHeader) MarshalJSON() ([]byte, error) {
type Alias RollupHeader
Expand Down
26 changes: 26 additions & 0 deletions go/common/rpc/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,29 @@ func FromRollupHeaderMsg(header *generated.RollupHeaderMsg) *common.RollupHeader
LastBatchSeqNo: header.LastBatchSeqNo,
}
}

func ToRollupDataMsg(rollupData *common.PublicRollupMetadata) generated.PublicRollupDataMsg {
if rollupData == nil {
return generated.PublicRollupDataMsg{}
}

return generated.PublicRollupDataMsg{StartSeq: rollupData.FirstBatchSequence.Uint64(), Timestamp: rollupData.StartTime}
}

func FromRollupDataMsg(msg *generated.PublicRollupDataMsg) (*common.PublicRollupMetadata, error) {
if msg.Timestamp == 0 {
return nil, fmt.Errorf("timestamp on the rollup can not be zero")
}

if msg.StartSeq == 0 {
return &common.PublicRollupMetadata{
FirstBatchSequence: nil,
StartTime: msg.Timestamp,
}, nil
}

return &common.PublicRollupMetadata{
FirstBatchSequence: big.NewInt(int64(msg.StartSeq)),
StartTime: msg.Timestamp,
}, nil
}
Loading

0 comments on commit a231667

Please sign in to comment.