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

Conversation

badgersrus
Copy link
Contributor

@badgersrus badgersrus commented Feb 26, 2024

Why this change is needed

We need to be able to retrieve some of the internal rollup data from the enclave when storing data in the host DB.

What changes were made as part of this PR

  • Add new GetRollupData that passes the internal CalldataRollupHeader byte slice as an argument and returns the CalldataRollupHeader.FirstBatchSequence and CalldataRollupHeader.StartTime

Testing

Can't see a simple way to unit test this so I just manually called the function processL1BlockTransactions and ran the full network simulation test and verified the data through console logs.

PR checks pre-merging

Please indicate below by ticking the checkbox that you have read and performed the required
PR checks

  • PR checks reviewed and performed

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

Thanks Will.
The approach is good.
Left a few comments

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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's better we return a "PublicRollupMetadata" struct (and a SystemError)

@@ -295,6 +296,15 @@ func (e *enclaveImpl) GetBatchBySeqNo(seqNo uint64) (*common.ExtBatch, common.Sy
return b, nil
}

func (e *enclaveImpl) GetRollupData(internalRollup []byte) (*big.Int, *uint64, common.SystemError) {
calldataRollupHeader := new(common.CalldataRollupHeader)
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 perfect stuff to retrieve from the database.
They should already be written in the "rollup" table.
It's a matter of selecting them from there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

logic looks good.
One small change to the grpc conversion

@@ -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 {
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

Copy link
Collaborator

@tudor-malene tudor-malene left a comment

Choose a reason for hiding this comment

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

lgtm

(one question)

@@ -76,10 +76,6 @@ func updateCanonicalValue(dbtx DBTransaction, isCanonical bool, values []common.
dbtx.ExecuteSQL(updateBatches, args...)
}

func FetchBlockHeader(db *sql.DB, hash common.L1BlockHash) (*types.Header, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

where has this gone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was unused so just got rid of it

@badgersrus badgersrus merged commit a231667 into main Feb 28, 2024
2 checks passed
@badgersrus badgersrus deleted the willh/enclave-api-get-batch-start-seq branch February 28, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants