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

Limit enclave fed L1 receipts to obscuro-relevant tx #1495

Merged
merged 5 commits into from
Sep 7, 2023

Conversation

BedrockSquirrel
Copy link
Collaborator

Why this change is needed

To keep costs down (both API usage and latency) we only want to request receipts for transactions that the enclave cares about (currently just management contract and message bus).

What changes were made as part of this PR

  • Wire the message bus address into the host so it's available
  • (As a related follow-up I also wired in the sequencer ID so we can get rid of the call to the enclave for that config)
  • When preparing receipts to send, only fetch the relevant ones
  • For now the list of receipts needs to be sparse so the indexes line up with the correct transactions because for some reason the transaction index doesn't seem to make it to the enclave.

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

@@ -125,8 +125,6 @@ type Enclave interface {
StreamL2Updates() (chan StreamL2UpdatesResponse, func())
// DebugEventLogRelevancy returns the logs of a transaction
DebugEventLogRelevancy(hash gethcommon.Hash) (json.RawMessage, SystemError)

Config() (*ObscuroEnclaveInfo, SystemError)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method existed because there was some config (sequencerID and message bus address) that wasn't available to the host but we wanted to serve those details on obscuroscan API. Since I needed one of them I thought I might as well add both properties and remove the method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it might still be useful in the HA setting.
Even as a sanity check to spot config problems early. Basically, when a host starts, or when an enclave is added, the host checks that the config matches the enclave

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we were planning to bake the static network level config into the enclave image which we sign. I agree something like that could be useful but I feel like we haven't reached our end-state of the config situation yet so kinda hard to predict.

Don't feel too strongly either way though, I can put it back if you prefer?

@@ -125,10 +131,52 @@ func (p HostInputConfig) ToHostConfig() *HostConfig {

// HostConfig contains the configuration used in the Obscuro host execution. Some fields are derived from the HostInputConfig.
type HostConfig struct {
/////
Copy link
Collaborator Author

@BedrockSquirrel BedrockSquirrel Sep 4, 2023

Choose a reason for hiding this comment

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

This config was getting huge, I tried to group it logically but happy to revert if this isn't helpful. Hoped it might inspire someone to think about how our config should be structured :)

@@ -44,13 +44,6 @@ func (m *blockMessageExtractor) Enabled() bool {
func (m *blockMessageExtractor) StoreCrossChainMessages(block *common.L1Block, receipts common.L1Receipts) error {
defer m.logger.Info("Block cross chain messages processed", log.BlockHashKey, block.Hash(), log.DurationKey, measure.NewStopwatch())

areReceiptsValid := common.VerifyReceiptHash(block, receipts)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We were verifying the receipt hash by reconstructing it using all the receipts but that check is not going to be feasible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

how can we do it? Using Merkle branches?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LLM has convinced me we could indeed provide a merkle proof for each receipt and that could give it high confidence the receipts are legit (so long as it can trust the receipt root hash).

Doesn't seem that hard to do but prefer to leave it out of this PR. Shall I leave a todo and create a GH issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually would we be able to do it without having to request all the receipt data... I guess not. So maybe we need to resign ourselves to doing a receipt lookup for every transaction anyway? We need to have a think about this.

I'm going to raise another PR that caches the receipts because part of the data problem is re-lookups when things are re-submitted I think.

@BedrockSquirrel BedrockSquirrel force-pushed the matt/only-submit-relevant-receipts branch from e98a6d8 to 8124a4f Compare September 4, 2023 14:59
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.

looks good.
Few questions

@@ -125,8 +125,6 @@ type Enclave interface {
StreamL2Updates() (chan StreamL2UpdatesResponse, func())
// DebugEventLogRelevancy returns the logs of a transaction
DebugEventLogRelevancy(hash gethcommon.Hash) (json.RawMessage, SystemError)

Config() (*ObscuroEnclaveInfo, 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 wonder if it might still be useful in the HA setting.
Even as a sanity check to spot config problems early. Basically, when a host starts, or when an enclave is added, the host checks that the config matches the enclave

@@ -44,13 +44,6 @@ func (m *blockMessageExtractor) Enabled() bool {
func (m *blockMessageExtractor) StoreCrossChainMessages(block *common.L1Block, receipts common.L1Receipts) error {
defer m.logger.Info("Block cross chain messages processed", log.BlockHashKey, block.Hash(), log.DurationKey, measure.NewStopwatch())

areReceiptsValid := common.VerifyReceiptHash(block, receipts)
Copy link
Collaborator

Choose a reason for hiding this comment

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

how can we do it? Using Merkle branches?

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

@BedrockSquirrel BedrockSquirrel merged commit b4cbf13 into main Sep 7, 2023
2 checks passed
@BedrockSquirrel BedrockSquirrel deleted the matt/only-submit-relevant-receipts branch September 7, 2023 09:25
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