Skip to content

Commit

Permalink
integrate plugin into sequencer (reverts??)
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Oct 18, 2024
1 parent 3d5ffa8 commit aebb260
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ sequencer:
--network sequencer \
--rpc-call-max-steps=4123000

sequencer-plugin:
./build/juno \
--http \
--http-port=6060 \
--http-host=0.0.0.0 \
--db-path=./seq-db \
--log-level=debug \
--seq-enable \
--seq-block-time=1 \
--network sequencer \
--plugin-path="myplugin.so" \
--rpc-call-max-steps=4123000

sequencer-with-accounts:
./build/juno \
--http \
Expand Down
15 changes: 14 additions & 1 deletion builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/feed"
"github.com/NethermindEth/juno/mempool"
"github.com/NethermindEth/juno/plugin"
"github.com/NethermindEth/juno/rpc"
"github.com/NethermindEth/juno/service"
"github.com/NethermindEth/juno/starknetdata"
Expand Down Expand Up @@ -62,6 +63,8 @@ type Builder struct {
chanFinalised chan struct{}

blockHashToBeRevealed *felt.Felt

plugin plugin.JunoPlugin
}

func New(privKey *ecdsa.PrivateKey, ownAddr *felt.Felt, bc *blockchain.Blockchain, builderVM vm.VM,
Expand Down Expand Up @@ -115,6 +118,11 @@ func (b *Builder) WithJunoEndpoint(endpoint string) *Builder {
return b
}

func (b *Builder) WithPlugin(plugin plugin.JunoPlugin) *Builder {
b.plugin = plugin
return b
}

func (b *Builder) WithSyncToBlock(syncTo uint64) *Builder {
b.shadowSyncToBlock = syncTo
return b
Expand Down Expand Up @@ -319,7 +327,12 @@ func (b *Builder) Finalise(signFunc blockchain.BlockSignFunc) error {
b.log.Infow("Finalised block", "number", b.pendingBlock.Block.Number, "hash",
b.pendingBlock.Block.Hash.ShortString(), "state", b.pendingBlock.Block.GlobalStateRoot.ShortString())
b.listener.OnBlockFinalised(b.pendingBlock.Block.Header)

if b.plugin != nil {
err := b.plugin.NewBlock(b.pendingBlock.Block, b.pendingBlock.StateUpdate, b.pendingBlock.NewClasses)
if err != nil {
b.log.Errorw("error sending new block to plugin", err)
}
}
if err := b.ClearPending(); err != nil {
return err
}
Expand Down
25 changes: 13 additions & 12 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,17 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
client := feeder.NewClient(cfg.Network.FeederURL).WithUserAgent(ua).WithLogger(log).
WithTimeout(cfg.GatewayTimeout).WithAPIKey(cfg.GatewayAPIKey)
starknetData := adaptfeeder.New(client)
var junoPlugin plugin.JunoPlugin
var rpcHandler *rpc.Handler
var synchronizer *sync.Synchronizer
var sequencer *builder.Builder
if cfg.PluginPath != "" {
junoPlugin, err = plugin.Load(cfg.PluginPath)
if err != nil {
return nil, err
}
services = append(services, plugin.NewService(junoPlugin))
}
if cfg.Sequencer {
if cfg.SeqShadowMode && chain.Network().L2ChainID != utils.Sepolia.L2ChainID {
return nil, fmt.Errorf("the sequencers shadow mode can only be used for %v network. Provided network: %v", utils.Sepolia, cfg.Network)
Expand All @@ -181,17 +190,17 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
}
poolDB, _ := pebble.NewMem()
p := mempool.New(poolDB)
sequencer := builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, //nolint:mnd
time.Second*time.Duration(cfg.SeqBlockTime), p, log)
sequencer = builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, //nolint:mnd
time.Second*time.Duration(cfg.SeqBlockTime), p, log).WithPlugin(junoPlugin)
if cfg.SeqShadowMode {
sequencer = builder.NewShadow(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, time.Second*time.Duration(cfg.SeqBlockTime), p, //nolint: gomnd,lll,mnd
log, starknetData).WithJunoEndpoint(cfg.SeqRPCEndpoint).WithSyncToBlock(cfg.SeqShadowModeSyncTo)
log, starknetData).WithJunoEndpoint(cfg.SeqRPCEndpoint).WithSyncToBlock(cfg.SeqShadowModeSyncTo).WithPlugin(junoPlugin)
}

rpcHandler = rpc.New(chain, sequencer, throttledVM, version, log).WithMempool(p).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps))
services = append(services, sequencer)
} else {
synchronizer = sync.New(chain, starknetData, log, cfg.PendingPollInterval, dbIsRemote)
synchronizer = sync.New(chain, starknetData, log, cfg.PendingPollInterval, dbIsRemote).WithPlugin(junoPlugin)
gatewayClient := gateway.NewClient(cfg.Network.GatewayURL, log).WithUserAgent(ua).WithAPIKey(cfg.GatewayAPIKey)

var p2pService *p2p.Service
Expand Down Expand Up @@ -235,14 +244,6 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
rpcHandler = rpc.New(chain, syncReader, throttledVM, version, log).WithGateway(gatewayClient).WithFeeder(client)
rpcHandler.WithFilterLimit(cfg.RPCMaxBlockScan).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps))
}
if cfg.PluginPath != "" {
p, err := plugin.Load(cfg.PluginPath)
if err != nil {
return nil, err
}
synchronizer.WithPlugin(p)
services = append(services, plugin.NewService(p))
}
services = append(services, rpcHandler)
// to improve RPC throughput we double GOMAXPROCS
maxGoroutines := 2 * runtime.GOMAXPROCS(0)
Expand Down

0 comments on commit aebb260

Please sign in to comment.