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

feat: Trusted auctioneer: Maintain a separate optimistic block fork #3

Merged

Conversation

bharath-123
Copy link
Collaborator

@bharath-123 bharath-123 commented Sep 23, 2024

For the trusted auctioneer, we want to maintain two separate forks of the Flame chain:

  1. The canonical chain which is updated by conductor
  2. An optimistically synced chain of which transactions are sent by the auctioneer via the StreamOptimisticBlock grpc method.

This PR adds support for maintaining an optimistic fork given a BaseBlock struct which will be received by the Flame trusted auctioneer via the StreamOptimisticBlock stream.

The following changes have been made:

  1. We add a method ExecuteOptimisticBlock which takes in a BaseBlock struct and creates an optimistic block which is inserted into the chain.
  2. We add a currentOptimisticBlock pointer in core.Blockchain which stores a pointer to the header of the current optimistic block. This pointer is updated after an optimistic block is successfully executed in ExecuteOptimisticBlock
  3. BuildPayloadArgs takes an extra parameter called overrideTransactions which is a list of transactions which will be executed over AstriaOrdered. This will be simpler rather than maintaining a separate mempool list like AstriaOrdered for optimistic block transactions. When we are executing the optimistic block we override the overrideTransactions list with the list of transactions in our optimistic block. It does not matter to us if the transactions do not execute as they will be removed from the mempool as this block is eventually executed by conductor.
  4. Add an IsOptimisticExecution flag during payload building. If this flag is true, reverting transactions are not removed from the mempool.
  5. Add unit tests for ExecuteOptimisticBlock

Note: If there are transactions which revert during optimistic execution, we do not care about removing them since they would eventually be removed during the actual block execution which would be done by conductor.

@bharath-123 bharath-123 changed the base branch from main to trusted-auctioneer September 23, 2024 11:32
@bharath-123 bharath-123 changed the title feat: Maintain a separate optimistic block form feat: Maintain a separate optimistic block fork Sep 23, 2024
@bharath-123 bharath-123 changed the title feat: Maintain a separate optimistic block fork feat: Trusted auctioneer[1]: Maintain a separate optimistic block fork Sep 23, 2024
@bharath-123 bharath-123 changed the title feat: Trusted auctioneer[1]: Maintain a separate optimistic block fork feat: Maintain a separate optimistic block fork Sep 23, 2024
@bharath-123 bharath-123 changed the title feat: Maintain a separate optimistic block fork feat: Trusted Auctioneer: Maintain a separate optimistic block fork Sep 23, 2024
@bharath-123 bharath-123 changed the title feat: Trusted Auctioneer: Maintain a separate optimistic block fork feat: Trusted auctioneer: Maintain a separate optimistic block fork Sep 24, 2024
@@ -231,6 +235,89 @@ func protoU128ToBigInt(u128 *primitivev1.Uint128) *big.Int {
return lo.Add(lo, hi)
}

func (s *ExecutionServiceServerV1Alpha2) ExecuteOptimisticBlock(ctx context.Context, req *optimsticPb.BaseBlock) (*astriaPb.Block, error) {
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 will be used in the streamExecuteOptimisticBlock grpc and we will move it out to its own package when we implement the grpc method.

@bharath-123 bharath-123 marked this pull request as ready for review October 1, 2024 18:10
currentSnapBlock atomic.Pointer[types.Header] // Current head of snap-sync
currentFinalBlock atomic.Pointer[types.Header] // Latest (consensus) finalized block
currentSafeBlock atomic.Pointer[types.Header] // Latest (consensus) safe block
currentBlock atomic.Pointer[types.Header] // Current head of the chain
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 can use this instead of maintaining a separate currentOptimisticBlock

}

// Build a payload to add to the chain
payloadAttributes := &miner.BuildPayloadArgs{
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 would want to validate the transactions before executing them. It might be cheaper than executing the transaction on a VM.

@bharath-123 bharath-123 force-pushed the bharath/implement-optimistic-fork-creation branch from 267d68a to e786668 Compare October 16, 2024 11:21
@bharath-123 bharath-123 force-pushed the bharath/implement-optimistic-fork-creation branch from eb28e72 to c925895 Compare October 29, 2024 08:01
@bharath-123 bharath-123 force-pushed the bharath/implement-optimistic-fork-creation branch from c85c783 to fe03e69 Compare January 9, 2025 09:48
@bharath-123 bharath-123 force-pushed the bharath/implement-optimistic-fork-creation branch from fe03e69 to 9f7886f Compare January 13, 2025 17:38
chore: Trusted Auctioneer: update the protos
feat: Trusted Auctioneer: Add initial set of metrics for auctioneer
feat: Trusted Auctioneer: Code cleanups
…-block

feat: Trusted Auctioneer: Add API to query the current optimistic block
feat: Trusted Auctioneer: Support unmarshalling signed allocations and placing it at the TOB
feat: Trusted Auctioneer: Add a cmd line flag to run a Flame node in auctioneer mode
refactor: Trusted Auctioneer: Separate execution api service and optimistic execution api service
feat: Trusted Auctioneer: Implement bundle streaming
…ecution

feat: Trusted Auctioneer: implement stream execute optimistic block
feat: Trusted Auctioneer: add event which is triggered when the mempool is cleared
feat: Trusted Auctioneer: Clear mempool when mempool state is reset
feat: Trusted auctioneer: use optimistic head event in txpool's maintanance loop
…k-event

feat:  Trusted auctioneer: Add an event for optimistic head creation
@bharath-123 bharath-123 merged commit 0e1b4a1 into trusted-auctioneer Jan 13, 2025
@bharath-123 bharath-123 mentioned this pull request Jan 13, 2025
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.

1 participant