Skip to content

Commit

Permalink
switch to PublicRollupMetadata and regen grpc interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
badgersrus committed Feb 28, 2024
1 parent da3be6e commit 971e954
Show file tree
Hide file tree
Showing 9 changed files with 624 additions and 612 deletions.
2 changes: 1 addition & 1 deletion go/common/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type Enclave interface {
GetBatchBySeqNo(seqNo uint64) (*ExtBatch, SystemError)

// GetRollupData - retrieve the first batch sequence and start time for a given rollup.
GetRollupData(internalRollup []byte) (*big.Int, *uint64, SystemError)
GetRollupData(internalRollup []byte) (*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.
Expand Down
18 changes: 18 additions & 0 deletions go/common/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,24 @@ 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
}

func (r *PublicRollupMetadata) Encoded() ([]byte, error) {
return rlp.EncodeToBytes(r)
}

func DecodePublicRollupMetadata(encoded []byte) (*PublicRollupMetadata, error) {
var rollupMetadata PublicRollupMetadata
if err := rlp.DecodeBytes(encoded, &rollupMetadata); err != nil {
return nil, err
}
return &rollupMetadata, nil
}

// MarshalJSON custom marshals the RollupHeader into a json
func (r *RollupHeader) MarshalJSON() ([]byte, error) {
type Alias RollupHeader
Expand Down
1,167 changes: 579 additions & 588 deletions go/common/rpc/generated/enclave.pb.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions go/common/rpc/generated/enclave.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ message GetRollupDataRequest {
}

message GetRollupDataResponse {
uint64 startSeq = 1;
uint64 timestamp = 2;
SystemError systemError = 3;
bytes rollupMetadata = 1;
SystemError systemError = 2;
}

message StreamL2UpdatesRequest {}
Expand Down
2 changes: 2 additions & 0 deletions go/common/rpc/generated/enclave_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions go/enclave/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,17 @@ func (e *enclaveImpl) GetBatchBySeqNo(seqNo uint64) (*common.ExtBatch, common.Sy
return b, nil
}

func (e *enclaveImpl) GetRollupData(internalRollup []byte) (*big.Int, *uint64, common.SystemError) {
func (e *enclaveImpl) GetRollupData(internalRollup []byte) (*common.PublicRollupMetadata, common.SystemError) {
calldataRollupHeader := new(common.CalldataRollupHeader)
err := e.decryptDecompressAndDeserialise(internalRollup, calldataRollupHeader)
if err != nil {
return nil, nil, err
return nil, err
}
metadata := &common.PublicRollupMetadata{
FirstBatchSequence: calldataRollupHeader.FirstBatchSequence,
StartTime: calldataRollupHeader.StartTime,
}
return calldataRollupHeader.FirstBatchSequence, &calldataRollupHeader.StartTime, nil
return metadata, nil
}

// Status is only implemented by the RPC wrapper
Expand Down
23 changes: 12 additions & 11 deletions go/enclave/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,23 +364,24 @@ func (s *RPCServer) GetBatchBySeqNo(_ context.Context, request *generated.GetBat
}

func (s *RPCServer) GetRollupData(_ context.Context, request *generated.GetRollupDataRequest) (*generated.GetRollupDataResponse, error) {
startSeqBigInt, timestampPtr, err := s.enclave.GetRollupData(request.InternalRollup)
rollupMetadata, err := s.enclave.GetRollupData(request.InternalRollup)
if err != nil {
s.logger.Error("Error rollup data", log.ErrKey, err)
s.logger.Error("Error fetching rollup metadata", log.ErrKey, err)
return nil, err
}
var startSeq uint64
if startSeqBigInt != nil {
startSeq = startSeqBigInt.Uint64()
}
if timestampPtr == nil {
s.logger.Error("timestamp is nil")
return nil, errors.New("timestamp is nil")

encodedRollup, encodingErr := rollupMetadata.Encoded()
var sysErr *generated.SystemError
if encodingErr != nil {
sysErr = &generated.SystemError{
ErrorCode: 2,
ErrorString: encodingErr.Error(),
}
}

return &generated.GetRollupDataResponse{
StartSeq: startSeq,
Timestamp: *timestampPtr,
RollupMetadata: encodedRollup,
SystemError: sysErr,
}, err
}

Expand Down
3 changes: 0 additions & 3 deletions go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,6 @@ func (g *Guardian) processL1BlockTransactions(block *common.L1Block) {
g.logger.Error("Could not decode rollup.", log.ErrKey, err)
}
err = g.db.AddRollupHeader(r, block)
if err != nil {
g.logger.Error("Could not decode rollup.", log.ErrKey, err)
}
if err != nil {
if errors.Is(err, errutil.ErrAlreadyExists) {
g.logger.Info("Rollup already stored", log.RollupHashKey, r.Hash())
Expand Down
6 changes: 3 additions & 3 deletions go/host/rpc/enclaverpc/enclave_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,15 @@ func (c *Client) GetBatchBySeqNo(seqNo uint64) (*common.ExtBatch, common.SystemE
return common.DecodeExtBatch(batchMsg.Batch)
}

func (c *Client) GetRollupData(internalRollup []byte) (*big.Int, *uint64, common.SystemError) {
func (c *Client) GetRollupData(internalRollup []byte) (*common.PublicRollupMetadata, common.SystemError) {
timeoutCtx, cancel := context.WithTimeout(context.Background(), c.config.EnclaveRPCTimeout)
defer cancel()

response, err := c.protoClient.GetRollupData(timeoutCtx, &generated.GetRollupDataRequest{InternalRollup: internalRollup})
if err != nil {
return nil, nil, fmt.Errorf("rpc GetBatchBySeqNo failed. Cause: %w", err)
return nil, fmt.Errorf("rpc GetRollupData failed. Cause: %w", err)
}
return new(big.Int).SetUint64(response.StartSeq), &response.Timestamp, nil
return common.DecodePublicRollupMetadata(response.RollupMetadata)
}

func (c *Client) StreamL2Updates() (chan common.StreamL2UpdatesResponse, func()) {
Expand Down

0 comments on commit 971e954

Please sign in to comment.