Skip to content

Commit 2e26e91

Browse files
authored
Merge pull request #4 from astriaorg/bharath/implement-optimistic-fork-event
feat: Trusted auctioneer: Add an event for optimistic head creation
2 parents 9f7886f + 19f8867 commit 2e26e91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5544
-1258
lines changed

.github/workflows/astria-build-and-publish-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ jobs:
7272
push: true
7373
tags: ${{ steps.metadata.outputs.tags }}
7474
labels: ${{ steps.metadata.outputs.labels }}
75-
project: w2d6w0spqz
75+
project: w2d6w0spqz

cmd/devp2p/internal/ethtest/suite_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestEthSuite(t *testing.T) {
6161
if err != nil {
6262
t.Fatalf("could not create new test suite: %v", err)
6363
}
64+
6465
for _, test := range suite.EthTests() {
6566
t.Run(test.Name, func(t *testing.T) {
6667
if test.Slow && testing.Short() {
@@ -149,5 +150,6 @@ func setupGeth(stack *node.Node, dir string) error {
149150
return fmt.Errorf("failed to register catalyst service: %v", err)
150151
}
151152
_, err = backend.BlockChain().InsertChain(chain.blocks[1:])
153+
backend.BlockChain().SetOptimistic(chain.blocks[len(chain.blocks)-1])
152154
return err
153155
}

cmd/geth/config.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"errors"
2222
"fmt"
2323
"github.com/ethereum/go-ethereum/eth/catalyst"
24+
"github.com/ethereum/go-ethereum/grpc/optimistic"
25+
"github.com/ethereum/go-ethereum/grpc/shared"
2426
"os"
2527
"reflect"
2628
"runtime"
@@ -206,11 +208,16 @@ func makeFullNode(ctx *cli.Context) *node.Node {
206208

207209
// Configure gRPC if requested.
208210
if ctx.IsSet(utils.GRPCEnabledFlag.Name) {
209-
serviceV1, err := execution.NewExecutionServiceServerV1(eth)
211+
sharedService, err := shared.NewSharedServiceContainer(eth)
210212
if err != nil {
211-
utils.Fatalf("failed to create execution service: %v", err)
213+
utils.Fatalf("failed to create shared service container: %v", err)
212214
}
213-
utils.RegisterGRPCExecutionService(stack, serviceV1, &cfg.Node)
215+
216+
serviceV1a2 := execution.NewExecutionServiceServerV1(sharedService)
217+
218+
optimisticServiceV1a1 := optimistic.NewOptimisticServiceV1Alpha(sharedService)
219+
220+
utils.RegisterGRPCServices(stack, serviceV1a2, optimisticServiceV1a1, optimisticServiceV1a1, &cfg.Node)
214221
}
215222

216223
// Add the Ethereum Stats daemon if requested.

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ var (
123123
utils.MinerRecommitIntervalFlag,
124124
utils.MinerPendingFeeRecipientFlag,
125125
utils.MinerNewPayloadTimeoutFlag, // deprecated
126+
utils.AuctioneerEnabledFlag,
126127
utils.NATFlag,
127128
utils.NoDiscoverFlag,
128129
utils.DiscoveryV4Flag,

cmd/utils/flags.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package utils
1919

2020
import (
21+
optimisticGrpc "buf.build/gen/go/astria/execution-apis/grpc/go/astria/auction/v1alpha1/auctionv1alpha1grpc"
2122
"context"
2223
"crypto/ecdsa"
2324
"encoding/hex"
@@ -769,6 +770,13 @@ var (
769770
Category: flags.APICategory,
770771
}
771772

773+
// auctioneer
774+
AuctioneerEnabledFlag = &cli.BoolFlag{
775+
Name: "auctioneer",
776+
Usage: "Enable the auctioneer server",
777+
Category: flags.MinerCategory,
778+
}
779+
772780
// Network Settings
773781
MaxPeersFlag = &cli.IntFlag{
774782
Name: "maxpeers",
@@ -1438,6 +1446,12 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
14381446
SetDataDir(ctx, cfg)
14391447
setSmartCard(ctx, cfg)
14401448

1449+
if ctx.Bool(AuctioneerEnabledFlag.Name) {
1450+
cfg.EnableAuctioneer = true
1451+
} else {
1452+
cfg.EnableAuctioneer = false
1453+
}
1454+
14411455
if ctx.IsSet(JWTSecretFlag.Name) {
14421456
cfg.JWTSecret = ctx.String(JWTSecretFlag.Name)
14431457
}
@@ -1987,10 +2001,10 @@ func RegisterGraphQLService(stack *node.Node, backend ethapi.Backend, filterSyst
19872001
}
19882002
}
19892003

1990-
// RegisterGRPCExecutionService adds the gRPC API to the node.
2004+
// RegisterGRPCServices adds the gRPC API to the node.
19912005
// It was done this way so that our grpc execution server can access the ethapi.Backend
1992-
func RegisterGRPCExecutionService(stack *node.Node, execServ astriaGrpc.ExecutionServiceServer, cfg *node.Config) {
1993-
if err := node.NewGRPCServerHandler(stack, execServ, cfg); err != nil {
2006+
func RegisterGRPCServices(stack *node.Node, execServ astriaGrpc.ExecutionServiceServer, optimisticExecutionServ optimisticGrpc.OptimisticExecutionServiceServer, auctionServiceServer optimisticGrpc.AuctionServiceServer, cfg *node.Config) {
2007+
if err := node.NewGRPCServerHandler(stack, execServ, optimisticExecutionServ, auctionServiceServer, cfg); err != nil {
19942008
Fatalf("Failed to register the gRPC service: %v", err)
19952009
}
19962010
}

core/blockchain.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,16 @@ type BlockChain struct {
220220
stateCache state.Database // State database to reuse between imports (contains state cache)
221221
txIndexer *txIndexer // Transaction indexer, might be nil if not enabled
222222

223-
hc *HeaderChain
224-
rmLogsFeed event.Feed
225-
chainFeed event.Feed
226-
chainSideFeed event.Feed
227-
chainHeadFeed event.Feed
228-
logsFeed event.Feed
229-
blockProcFeed event.Feed
230-
scope event.SubscriptionScope
231-
genesisBlock *types.Block
223+
hc *HeaderChain
224+
rmLogsFeed event.Feed
225+
chainFeed event.Feed
226+
chainSideFeed event.Feed
227+
chainHeadFeed event.Feed
228+
chainOptimisticHeadFeed event.Feed
229+
logsFeed event.Feed
230+
blockProcFeed event.Feed
231+
scope event.SubscriptionScope
232+
genesisBlock *types.Block
232233

233234
// This mutex synchronizes chain write operations.
234235
// Readers don't need to take it, they can just read the database.
@@ -644,13 +645,16 @@ func (bc *BlockChain) SetSafe(header *types.Header) {
644645
}
645646

646647
// SetOptimistic sets the optimistic block.
647-
func (bc *BlockChain) SetOptimistic(header *types.Header) {
648+
func (bc *BlockChain) SetOptimistic(block *types.Block) {
649+
header := block.Header()
648650
bc.currentOptimisticBlock.Store(header)
649651
if header != nil {
650652
headOptimisticBlockGauge.Update(int64(header.Number.Uint64()))
651653
} else {
652654
headOptimisticBlockGauge.Update(0)
653655
}
656+
657+
bc.chainOptimisticHeadFeed.Send(ChainOptimisticHeadEvent{Block: block})
654658
}
655659

656660
// rewindHashHead implements the logic of rewindHead in the context of hash scheme.

core/blockchain_reader.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Su
445445
return bc.scope.Track(bc.chainHeadFeed.Subscribe(ch))
446446
}
447447

448+
// SubscribeChainOptimisticHeadEvent registers a subscription of ChainOptimisticHeadEvent.
449+
func (bc *BlockChain) SubscribeChainOptimisticHeadEvent(ch chan<- ChainOptimisticHeadEvent) event.Subscription {
450+
return bc.scope.Track(bc.chainOptimisticHeadFeed.Subscribe(ch))
451+
}
452+
448453
// SubscribeChainSideEvent registers a subscription of ChainSideEvent.
449454
func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Subscription {
450455
return bc.scope.Track(bc.chainSideFeed.Subscribe(ch))

core/events.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ import (
2424
// NewTxsEvent is posted when a batch of transactions enter the transaction pool.
2525
type NewTxsEvent struct{ Txs []*types.Transaction }
2626

27+
// NewMempoolClearedEvent is posted when the mempool is cleared after a head reset for trusted auctioneer
28+
type NewMempoolCleared struct {
29+
// the new head to which the mempool state was reset to before clearing the mempool
30+
NewHead *types.Header
31+
}
32+
2733
// NewMinedBlockEvent is posted when a block has been imported.
2834
type NewMinedBlockEvent struct{ Block *types.Block }
2935

@@ -41,3 +47,7 @@ type ChainSideEvent struct {
4147
}
4248

4349
type ChainHeadEvent struct{ Block *types.Block }
50+
51+
type ChainOptimisticHeadEvent struct {
52+
Block *types.Block
53+
}

core/txpool/blobpool/blobpool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,6 +1602,10 @@ func (p *BlobPool) SubscribeTransactions(ch chan<- core.NewTxsEvent, reorgs bool
16021602
}
16031603
}
16041604

1605+
func (p *BlobPool) SubscribeMempoolClearance(ch chan<- core.NewMempoolCleared) event.Subscription {
1606+
return nil
1607+
}
1608+
16051609
// Nonce returns the next nonce of an account, with all transactions executable
16061610
// by the pool already applied on top.
16071611
func (p *BlobPool) Nonce(addr common.Address) uint64 {

0 commit comments

Comments
 (0)