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

Node: Multithreaded processor #3

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion node/cmd/guardiand/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ var (
chainGovernorEnabled *bool
governorFlowCancelEnabled *bool

processorWorkerFactor *float64

ccqEnabled *bool
ccqAllowedRequesters *string
ccqP2pPort *uint
Expand Down Expand Up @@ -450,6 +452,7 @@ func init() {

chainGovernorEnabled = NodeCmd.Flags().Bool("chainGovernorEnabled", false, "Run the chain governor")
governorFlowCancelEnabled = NodeCmd.Flags().Bool("governorFlowCancelEnabled", false, "Enable flow cancel on the governor")
processorWorkerFactor = NodeCmd.Flags().Float64("processorWorkerFactor", 0.0, "Multiplied by the number of available CPUs on the system to determine the number of workers that the processor uses. 0.0 means single worker")

ccqEnabled = NodeCmd.Flags().Bool("ccqEnabled", false, "Enable cross chain query support")
ccqAllowedRequesters = NodeCmd.Flags().String("ccqAllowedRequesters", "", "Comma separated list of signers allowed to submit cross chain queries")
Expand Down Expand Up @@ -1639,7 +1642,7 @@ func runNode(cmd *cobra.Command, args []string) {
node.GuardianOptionAdminService(*adminSocketPath, ethRPC, ethContract, rpcMap),
node.GuardianOptionP2P(p2pKey, *p2pNetworkID, *p2pBootstrap, *nodeName, *subscribeToVAAs, *disableHeartbeatVerify, *p2pPort, *ccqP2pBootstrap, *ccqP2pPort, *ccqAllowedPeers, *gossipAdvertiseAddress, ibc.GetFeatures),
node.GuardianOptionStatusServer(*statusAddr),
node.GuardianOptionProcessor(*p2pNetworkID),
node.GuardianOptionProcessor(*p2pNetworkID, *processorWorkerFactor),
}

if shouldStart(publicGRPCSocketPath) {
Expand Down
3 changes: 2 additions & 1 deletion node/pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -196,7 +197,7 @@ func mockGuardianRunnable(t testing.TB, gs []*mockGuardian, mockGuardianIndex ui
GuardianOptionPublicWeb(cfg.publicWeb, cfg.publicSocket, "", false, ""),
GuardianOptionAdminService(cfg.adminSocket, nil, nil, rpcMap),
GuardianOptionStatusServer(fmt.Sprintf("[::]:%d", cfg.statusPort)),
GuardianOptionProcessor(networkID),
GuardianOptionProcessor(networkID, 3.0/float64(runtime.NumCPU())), // Create three workers.
}

guardianNode := NewGuardianNode(
Expand Down
3 changes: 2 additions & 1 deletion node/pkg/node/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func GuardianOptionDatabase(db *db.Database) *GuardianOption {

// GuardianOptionProcessor enables the default processor, which is required to make consensus on messages.
// Dependencies: db, governor, accountant
func GuardianOptionProcessor(networkId string) *GuardianOption {
func GuardianOptionProcessor(networkId string, workerFactor float64) *GuardianOption {
return &GuardianOption{
name: "processor",
// governor and accountant may be set to nil, but that choice needs to be made before the processor is configured
Expand All @@ -600,6 +600,7 @@ func GuardianOptionProcessor(networkId string) *GuardianOption {
g.acctC.readC,
g.gatewayRelayer,
networkId,
workerFactor,
).Run

return nil
Expand Down
3 changes: 1 addition & 2 deletions node/pkg/processor/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,10 @@ func createProcessorForTest(b *testing.B, numVAAs int, ctx context.Context, db *
gossipAttestationSendC: pd.gossipAttestationSendC,
gossipVaaSendC: pd.gossipVaaSendC,
guardianSigner: ourSigner,
gs: gs,
gst: gst,
db: db,
logger: logger,
state: &aggregationState{observationMap{}},
state: &aggregationState{signatures: observationMap{}},
ourAddr: crypto.PubkeyToAddress(ourSigner.PublicKey()),
pythnetVaas: make(map[string]PythNetVaaEntry),
updatedVAAs: make(map[string]*updateVaaEntry),
Expand Down
Loading
Loading