Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new GetRollupData API to enclave client #1815

Merged
merged 15 commits into from
Feb 28, 2024
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
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is one way to marshal the metadata object.
The other way (which is what we've mostly done) is to use the "converters" in the grpc classes).

You can have a look at CrossChainMsg , as an example

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
Loading