Skip to content

Commit

Permalink
Merge pull request #2759 from oasislabs/ptrus/feature/runtime-workload
Browse files Browse the repository at this point in the history
txsource: runtime workload
  • Loading branch information
ptrus authored Mar 19, 2020
2 parents 40d77ef + 3e15dfa commit 3a09db5
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .changelog/2759.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
txsource: add a runtime workload

The added runtime workload submits simiple-keyvalue runtime requests.
1 change: 1 addition & 0 deletions go/oasis-node/cmd/debug/txsource/txsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func init() {
_ = viper.BindPFlags(fs)
txsourceCmd.Flags().AddFlagSet(fs)

txsourceCmd.Flags().AddFlagSet(workload.RuntimeFlags)
txsourceCmd.Flags().AddFlagSet(cmdGrpc.ClientFlags)
txsourceCmd.Flags().AddFlagSet(cmdFlags.DebugTestEntityFlags)
txsourceCmd.Flags().AddFlagSet(cmdFlags.GenesisFileFlags)
Expand Down
9 changes: 8 additions & 1 deletion go/oasis-node/cmd/debug/txsource/workload/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,14 @@ func (d *delegation) doReclaimEscrowTx(ctx context.Context, rng *rand.Rand, cnsc
return nil
}

func (d *delegation) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.ClientConn, cnsc consensus.ClientBackend, rtc runtimeClient.RuntimeClient, fundingAccount signature.Signer) error {
func (d *delegation) Run(
gracefulExit context.Context,
rng *rand.Rand,
conn *grpc.ClientConn,
cnsc consensus.ClientBackend,
rtc runtimeClient.RuntimeClient,
fundingAccount signature.Signer,
) error {
var err error
ctx := context.Background()

Expand Down
9 changes: 8 additions & 1 deletion go/oasis-node/cmd/debug/txsource/workload/oversized.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ var oversizedLogger = logging.GetLogger("cmd/txsource/workload/oversized")

type oversized struct{}

func (oversized) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.ClientConn, cnsc consensus.ClientBackend, rtc runtimeClient.RuntimeClient, fundingAccount signature.Signer) error {
func (oversized) Run(
gracefulExit context.Context,
rng *rand.Rand,
conn *grpc.ClientConn,
cnsc consensus.ClientBackend,
rtc runtimeClient.RuntimeClient,
fundingAccount signature.Signer,
) error {
txSignerFactory := memorySigner.NewFactory()
txSigner, err := txSignerFactory.Generate(signature.SignerEntity, rng)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion go/oasis-node/cmd/debug/txsource/workload/parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ var parallelLogger = logging.GetLogger("cmd/txsource/workload/parallel")

type parallel struct{}

func (parallel) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.ClientConn, cnsc consensus.ClientBackend, rtc runtimeClient.RuntimeClient, fundingAccount signature.Signer) error {
func (parallel) Run(
gracefulExit context.Context,
rng *rand.Rand,
conn *grpc.ClientConn,
cnsc consensus.ClientBackend,
rtc runtimeClient.RuntimeClient,
fundingAccount signature.Signer,
) error {
ctx := context.Background()
var err error

Expand Down
28 changes: 18 additions & 10 deletions go/oasis-node/cmd/debug/txsource/workload/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
registryNodeMaxEpochUpdate = 5
)

var registryLogger = logging.GetLogger("cmd/txsource/workload/registry")
var registrationLogger = logging.GetLogger("cmd/txsource/workload/registration")

type registration struct {
ns common.Namespace
Expand Down Expand Up @@ -142,7 +142,7 @@ func signNode(identity *identity.Identity, nodeDesc *node.Node) (*node.MultiSign

sigNode, err := node.MultiSignNode(nodeSigners, registry.RegisterNodeSignatureContext, nodeDesc)
if err != nil {
registryLogger.Error("failed to sign node descriptor",
registrationLogger.Error("failed to sign node descriptor",
"err", err,
)
return nil, err
Expand All @@ -151,18 +151,26 @@ func signNode(identity *identity.Identity, nodeDesc *node.Node) (*node.MultiSign
return sigNode, nil
}

func (r *registration) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.ClientConn, cnsc consensus.ClientBackend, rtc runtimeClient.RuntimeClient, fundingAccount signature.Signer) error { // nolint: gocyclo
func (r *registration) Run( // nolint: gocyclo
gracefulExit context.Context,
rng *rand.Rand,
conn *grpc.ClientConn,
cnsc consensus.ClientBackend,
rtc runtimeClient.RuntimeClient,
fundingAccount signature.Signer,
) error {
ctx := context.Background()
var err error

// Non-existing runtime.
if err = r.ns.UnmarshalHex("0000000000000000000000000000000000000000000000000000000000000002"); err != nil {
panic(err)
}

baseDir := viper.GetString(cmdCommon.CfgDataDir)
nodeIdentitiesDir := filepath.Join(baseDir, "node-identities")
if err = common.Mkdir(nodeIdentitiesDir); err != nil {
return fmt.Errorf("txsource/registry: failed to create node-identities dir: %w", err)
return fmt.Errorf("txsource/registration: failed to create node-identities dir: %w", err)
}

// Load all accounts.
Expand Down Expand Up @@ -249,7 +257,7 @@ func (r *registration) Run(gracefulExit context.Context, rng *rand.Rand, conn *g
}

// Fund entity account to cover registration fees.
if err = transferFunds(ctx, registryLogger, cnsc, fundingAccount, entityAccs[i].signer.Public(), feeAmount); err != nil {
if err = transferFunds(ctx, registrationLogger, cnsc, fundingAccount, entityAccs[i].signer.Public(), feeAmount); err != nil {
return fmt.Errorf("account funding failure: %w", err)
}

Expand Down Expand Up @@ -286,7 +294,7 @@ func (r *registration) Run(gracefulExit context.Context, rng *rand.Rand, conn *g
}

// Fund entity account to cover entity registration fees.
if err = transferFunds(ctx, registryLogger, cnsc, fundingAccount, entityAccs[i].signer.Public(), feeAmount); err != nil {
if err = transferFunds(ctx, registrationLogger, cnsc, fundingAccount, entityAccs[i].signer.Public(), feeAmount); err != nil {
return fmt.Errorf("account funding failure: %w", err)
}

Expand Down Expand Up @@ -337,7 +345,7 @@ func (r *registration) Run(gracefulExit context.Context, rng *rand.Rand, conn *g
}

// Fund node account to cover registration fees.
if err = transferFunds(ctx, registryLogger, cnsc, fundingAccount, selectedNode.id.NodeSigner.Public(), int64(feeAmount)); err != nil {
if err = transferFunds(ctx, registrationLogger, cnsc, fundingAccount, selectedNode.id.NodeSigner.Public(), int64(feeAmount)); err != nil {
return fmt.Errorf("account funding failure: %w", err)
}
selectedNode.reckonedNonce++
Expand All @@ -346,20 +354,20 @@ func (r *registration) Run(gracefulExit context.Context, rng *rand.Rand, conn *g
if err != nil {
return fmt.Errorf("transaction.Sign: %w", err)
}
registryLogger.Debug("submitting registration",
registrationLogger.Debug("submitting registration",
"node", selectedNode.nodeDesc,
)
if err = cnsc.SubmitTx(ctx, signedTx); err != nil {
return fmt.Errorf("cnsc.SubmitTx: %w", err)
}
registryLogger.Debug("registered node",
registrationLogger.Debug("registered node",
"node", selectedNode.nodeDesc,
)

select {
case <-time.After(1 * time.Second):
case <-gracefulExit.Done():
registryLogger.Debug("time's up")
registrationLogger.Debug("time's up")
return nil
}
}
Expand Down
Loading

0 comments on commit 3a09db5

Please sign in to comment.