Skip to content

Commit

Permalink
w1p: Multiple validators
Browse files Browse the repository at this point in the history
  • Loading branch information
abukosek committed Oct 13, 2020
1 parent cd127b2 commit b487942
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
46 changes: 43 additions & 3 deletions go/extra/conbench/cmd/conbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type localAccount struct {
addr staking.Address
cachedNonce uint64
cachedGas uint64
errorCount map[error]uint64
}

func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccount, toAddr staking.Address, amount uint64, noCache, noWait bool) error {
Expand All @@ -99,6 +100,7 @@ func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccoun
Height: consensus.HeightLatest,
})
if err != nil {
from.errorCount[err]++
return fmt.Errorf("unable to get sender's nonce: %w", err)
}
atomic.StoreUint64(&from.cachedNonce, nonce)
Expand All @@ -109,6 +111,7 @@ func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccoun
To: toAddr,
}
if err = transfer.Amount.FromUint64(amount); err != nil {
from.errorCount[err]++
return fmt.Errorf("unable to convert given amount from uint64: %w", err)
}

Expand All @@ -123,6 +126,7 @@ func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccoun
Transaction: tx,
})
if grr != nil {
from.errorCount[grr]++
return fmt.Errorf("unable to estimate gas: %w", grr)
}
gas = uint64(estGas)
Expand All @@ -131,11 +135,13 @@ func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccoun

tx.Fee.Gas = transaction.Gas(gas)
if err = tx.Fee.Amount.FromUint64(gas * viper.GetUint64(CfgGasPrice)); err != nil {
from.errorCount[err]++
return fmt.Errorf("unable to convert fee amount from uint64: %w", err)
}

signedTx, err := transaction.Sign(from.signer, tx)
if err != nil {
from.errorCount[err]++
return fmt.Errorf("unable to sign transfer transaction: %w", err)
}

Expand All @@ -144,7 +150,11 @@ func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccoun

if noWait {
// Submit transaction, but don't wait for it to be included in a block.
return cc.SubmitTxNoWait(ctx, signedTx)
grr := cc.SubmitTxNoWait(ctx, signedTx)
if grr != nil {
from.errorCount[grr]++
}
return grr
}

// Otherwise, submit and wait for the txn to be included in a block.
Expand All @@ -155,6 +165,7 @@ func transfer(ctx context.Context, cc consensus.ClientBackend, from *localAccoun
submissionCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
if err = cc.SubmitTx(submissionCtx, signedTx); err != nil {
from.errorCount[err]++
return err
}
return nil
Expand Down Expand Up @@ -286,6 +297,7 @@ func doRun(cmd *cobra.Command, args []string) error { // nolint: gocyclo
account[a].addr = staking.NewAddress(signer.Public())
account[a].cachedNonce = notYetCached
account[a].cachedGas = notYetCached
account[a].errorCount = make(map[error]uint64)
}

var fundingSigner signature.Signer
Expand Down Expand Up @@ -427,7 +439,9 @@ func doRun(cmd *cobra.Command, args []string) error { // nolint: gocyclo
}
if noWait {
// Send transactions until terminated.
// Ignore cache because it results in too many errors.
s = 0
noCache = true
}

fromIdx := idx
Expand All @@ -439,16 +453,16 @@ func doRun(cmd *cobra.Command, args []string) error { // nolint: gocyclo
atomic.AddUint64(&numSubmitErrors, 1)
// Disable cache for the next sample, just in case
// we messed up the nonce or if the gas cost changed.
noCache = true
if !noWait {
noCache = true
doneCh <- true
}
continue
}
atomic.AddUint64(&totalSubmitTimeNs, uint64(time.Since(startT).Nanoseconds()))
atomic.AddUint64(&numSubmitSamples, 1)
noCache = false
if !noWait {
noCache = false
doneCh <- true
}
}
Expand Down Expand Up @@ -565,6 +579,29 @@ func doRun(cmd *cobra.Command, args []string) error { // nolint: gocyclo
}
}

// Collect number of transfer errors from all accounts.
errCounts := make(map[string]uint64)
for a := range account {
for e, c := range account[a].errorCount {
er := strings.ReplaceAll(e.Error(), " ", "_")
er = strings.ReplaceAll(er, "\"", "'")
errCounts[er] += c
}
}
// Output the results sorted by key.
keys := make([]string, 0, len(errCounts))
for k := range errCounts {
keys = append(keys, k)
}
sort.Strings(keys)
errCountsString := ""
for _, k := range keys {
if errCountsString != "" {
errCountsString += " "
}
errCountsString += k + "#" + fmt.Sprintf("%v", errCounts[k])
}

logger.Info("benchmark finished",
// Number of accounts involved in benchmark (level of parallelism).
"num_accounts", numAccounts,
Expand Down Expand Up @@ -600,6 +637,9 @@ func doRun(cmd *cobra.Command, args []string) error { // nolint: gocyclo
"block_delta_t_s", strings.Trim(fmt.Sprint(blockDeltaT), "[]"),
// Maximum average tps over a sliding window.
"max_avg_tps", bestAvgTps,
// Map of errors that occurred during benchmarking (if any).
// These are sorted by key.
"error_counts", errCountsString,
)

// Refund money into original funding account.
Expand Down
3 changes: 2 additions & 1 deletion go/extra/conbench/conbench-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ printf "${GRN}### Starting the test network...${OFF}\n"
${OASIS_NET_RUNNER} \
--fixture.default.setup_runtimes=false \
--fixture.default.num_entities=1 \
--fixture.default.num_validators=4 \
--fixture.default.disable_supplementary_sanity_checks=true \
--fixture.default.timeout_commit=1ms \
--fixture.default.timeout_commit=100ms \
--basedir.no_temp_dir \
--basedir "${TEST_BASE_DIR}" &

Expand Down
8 changes: 8 additions & 0 deletions go/oasis-net-runner/fixtures/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
cfgKeymanagerBinary = "fixture.default.keymanager.binary"
cfgNodeBinary = "fixture.default.node.binary"
cfgNumEntities = "fixture.default.num_entities"
cfgNumValidators = "fixture.default.num_validators"
cfgRuntimeBinary = "fixture.default.runtime.binary"
cfgRuntimeGenesisState = "fixture.default.runtime.genesis_state"
cfgRuntimeLoader = "fixture.default.runtime.loader"
Expand Down Expand Up @@ -84,6 +85,12 @@ func newDefaultFixture() (*oasis.NetworkFixture, error) {
fixture.Entities = append(fixture.Entities, oasis.EntityCfg{})
}

for i := 0; i < viper.GetInt(cfgNumValidators); i++ {
fixture.Validators = append(fixture.Validators, oasis.ValidatorFixture{
Entity: 1, Consensus: oasis.ConsensusFixture{DisableSupplementarySanityChecks: viper.GetBool(cfgDisableSupSanityChecks)},
})
}

if viper.GetBool(cfgSetupRuntimes) {
fixture.Runtimes = []oasis.RuntimeFixture{
// Key manager runtime.
Expand Down Expand Up @@ -156,6 +163,7 @@ func init() {
DefaultFixtureFlags.Bool(cfgSetupRuntimes, true, "initialize the network with runtimes and runtime nodes")
DefaultFixtureFlags.Bool(cfgDisableSupSanityChecks, false, "disable supplementary sanity checks")
DefaultFixtureFlags.Int(cfgNumEntities, 1, "number of (non debug) entities in genesis")
DefaultFixtureFlags.Int(cfgNumValidators, 1, "number of validator nodes")
DefaultFixtureFlags.String(cfgKeymanagerBinary, "simple-keymanager", "path to the keymanager runtime")
DefaultFixtureFlags.String(cfgNodeBinary, "oasis-node", "path to the oasis-node binary")
DefaultFixtureFlags.String(cfgRuntimeBinary, "simple-keyvalue", "path to the runtime binary")
Expand Down

0 comments on commit b487942

Please sign in to comment.