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

tools: update block-generator to use conduit binary #5306

Merged
merged 7 commits into from
Apr 20, 2023
Merged
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
34 changes: 28 additions & 6 deletions tools/block-generator/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type GenerationConfig struct {
GenesisAccountInitialBalance uint64 `yaml:"genesis_account_balance"`

// Block generation
TxnPerBlock uint64 `mapstructure:"tx_per_block"`
TxnPerBlock uint64 `yaml:"tx_per_block"`

// TX Distribution
PaymentTransactionFraction float32 `yaml:"tx_pay_fraction"`
Expand Down Expand Up @@ -120,7 +120,7 @@ func MakeGenerator(config GenerationConfig) (Generator, error) {
genesisHash: [32]byte{},
genesisID: "blockgen-test",
prevBlockHash: "",
round: 1,
round: 0,
txnCounter: 0,
timestamp: 0,
rewardsLevel: 0,
Expand Down Expand Up @@ -312,7 +312,9 @@ func (g *generator) WriteGenesis(output io.Writer) error {
FeeSink: g.feeSink.String(),
Timestamp: g.timestamp,
}
return json.NewEncoder(output).Encode(gen)

_, err := output.Write(protocol.EncodeJSON(gen))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genesis response needs to be msgp encoded.

return err
}

func getTransactionOptions() []interface{} {
Expand Down Expand Up @@ -357,12 +359,28 @@ func (g *generator) finishRound(txnCount uint64) {

// WriteBlock generates a block full of new transactions and writes it to the writer.
func (g *generator) WriteBlock(output io.Writer, round uint64) error {

if round != g.round {
fmt.Printf("Generator only supports sequential block access. Expected %d but received request for %d.\n", g.round, round)
}

numTxnForBlock := g.txnForRound(round)

// return genesis block
if round == 0 {
// write the msgpack bytes for a block
block, err := rpcs.RawBlockBytes(g.ledger, basics.Round(round))
if err != nil {
return err
}
_, err = output.Write(block)
if err != nil {
return err
}
g.finishRound(numTxnForBlock)
return nil
}
Copy link
Contributor Author

@shiqizng shiqizng Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

postgresql exporter adds blocks starting from round 0.


header := bookkeeping.BlockHeader{
Round: basics.Round(g.round),
Branch: bookkeeping.BlockHash{},
Expand Down Expand Up @@ -414,15 +432,19 @@ func (g *generator) WriteBlock(output io.Writer, round uint64) error {
Certificate: agreement.Certificate{},
}

err := json.NewEncoder(output).Encode(cert)
err := g.ledger.AddBlock(cert.Block, cert.Certificate)
if err != nil {
return err
}
// write the msgpack bytes for a block
block, err := rpcs.RawBlockBytes(g.ledger, basics.Round(round))
if err != nil {
return err
}
err = g.ledger.AddBlock(cert.Block, agreement.Certificate{})
_, err = output.Write(block)
if err != nil {
return err
}
g.ledger.WaitForCommit(basics.Round(g.round))
g.finishRound(numTxnForBlock)
return nil
}
Expand Down
1 change: 1 addition & 0 deletions tools/block-generator/generator/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func TestWriteRound(t *testing.T) {
g := makePrivateGenerator(t)
var data []byte
writer := bytes.NewBuffer(data)
g.WriteBlock(writer, 0)
g.WriteBlock(writer, 1)
var block rpcs.EncodedBlockCert
protocol.Decode(data, &block)
Expand Down
24 changes: 12 additions & 12 deletions tools/block-generator/generator/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,61 +53,61 @@ func TestParseURL(t *testing.T) {
var testcases = []struct {
name string
url string
expectedRound string
expectedParam string
shiqizng marked this conversation as resolved.
Show resolved Hide resolved
err string
}{
{
name: "no block",
url: "/v2/blocks/",
expectedRound: "",
expectedParam: "",
err: "invalid request path, /v2/blocks/",
},
{
name: "normal one digit",
url: fmt.Sprintf("%s1", blockQueryPrefix),
expectedRound: "1",
expectedParam: "1",
err: "",
},
{
name: "normal long number",
url: fmt.Sprintf("%s12345678", blockQueryPrefix),
expectedRound: "12345678",
expectedParam: "12345678",
err: "",
},
{
name: "with query parameters",
url: fmt.Sprintf("%s1234?pretty", blockQueryPrefix),
expectedRound: "1234",
expectedParam: "1234",
err: "",
},
{
name: "with query parameters",
url: fmt.Sprintf("%s1234?pretty", blockQueryPrefix),
expectedRound: "1234",
expectedParam: "1234",
err: "",
},
{
name: "no deltas",
url: "/v2/deltas/",
expectedRound: "",
expectedParam: "",
err: "invalid request path, /v2/deltas/",
},
{
name: "deltas",
url: fmt.Sprintf("%s123?Format=msgp", deltaQueryPrefix),
expectedRound: "123",
expectedParam: "123",
err: "",
},
{
name: "no account",
url: "/v2/accounts/",
expectedRound: "",
expectedParam: "",
err: "invalid request path, /v2/accounts/",
},
{
name: "accounts",
url: fmt.Sprintf("%sAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGFFWAF4", accountQueryPrefix),
expectedRound: "AIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGFFWAF4",
expectedParam: "AIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGFFWAF4",
err: "",
},
}
Expand All @@ -117,9 +117,9 @@ func TestParseURL(t *testing.T) {
round, err := parseURL(testcase.url)
if len(testcase.err) == 0 {
msg := fmt.Sprintf("Unexpected error parsing '%s', expected round '%s' received error: %v",
testcase.url, testcase.expectedRound, err)
testcase.url, testcase.expectedParam, err)
require.NoError(t, err, msg)
assert.Equal(t, testcase.expectedRound, round)
assert.Equal(t, testcase.expectedParam, round)
} else {
require.Error(t, err, fmt.Sprintf("Expected an error containing: %s", testcase.err))
require.True(t, strings.Contains(err.Error(), testcase.err))
Expand Down
42 changes: 0 additions & 42 deletions tools/block-generator/metrics/metrics.go

This file was deleted.

56 changes: 0 additions & 56 deletions tools/block-generator/run_generator.sh

This file was deleted.

2 changes: 1 addition & 1 deletion tools/block-generator/run_postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# in a debugger. Simply start this script and run with:
# ./block-generator runner \
# -d 5s \
# -i ./../algorand-indexer/algorand-indexer \
# -i <path to conduit binary> \
# -c "host=localhost user=algorand password=algorand dbname=algorand port=15432 sslmode=disable" \
# -r results \
# -s scenarios/config.payment.small.yml
Expand Down
13 changes: 8 additions & 5 deletions tools/block-generator/run_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

set -e

CONDUIT_BINARY=$1
if [ -z "$CONDUIT_BINARY" ]; then
echo "path to conduit binary is required"
exit 1
fi

POSTGRES_CONTAINER=generator-test-container
POSTGRES_PORT=15432
POSTGRES_DATABASE=generator_db
CONFIG=${1:-"$(dirname $0)/test_config.yml"}
CONFIG=${2:-"$(dirname $0)/test_config.yml"}
echo "Using config file: $CONFIG"

function start_postgres() {
Expand Down Expand Up @@ -38,15 +44,12 @@ rm -rf OUTPUT_RUN_RUNNER_TEST > /dev/null 2>&1
echo "Building generator."
pushd $(dirname "$0") > /dev/null
go build
cd ../.. > /dev/null
echo "Building indexer."
make
popd
echo "Starting postgres container."
start_postgres
echo "Starting test runner"
$(dirname "$0")/block-generator runner \
--indexer-binary ../algorand-indexer/algorand-indexer \
--conduit-binary "$CONDUIT_BINARY" \
--report-directory OUTPUT_RUN_RUNNER_TEST \
--test-duration 30s \
--log-level trace \
Expand Down
19 changes: 9 additions & 10 deletions tools/block-generator/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

CONNECTION_STRING=""
INDEXER_BINARY=""
CONDUIT_BINARY=""
REPORT_DIR=""
DURATION="1h"
LOG_LEVEL="error"
Expand All @@ -17,7 +17,7 @@ help() {
echo " -r|--report-dir directory where the report should be written."
echo " -d|--duration test duration."
echo " -l|--level log level to pass to Indexer."
echo " -g|--generator use a different indexer binary to run the generator."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's no longer part of the indexer binary, this should be required. Mark as required on line 79

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

echo " -g|--generator block-generator binary to run the generator."
exit
}

Expand All @@ -34,7 +34,7 @@ while :; do
shift
;;
-i | --indexer)
INDEXER_BINARY="${2-}"
CONDUIT_BINARY="${2-}"
shift
;;
-r | --report-dir)
Expand Down Expand Up @@ -66,7 +66,7 @@ if [ -z "$CONNECTION_STRING" ]; then
exit 1
fi

if [ -z "$INDEXER_BINARY" ]; then
if [ -z "$CONDUIT_BINARY" ]; then
echo "Missing required indexer binary parameter (-i / --indexer)."
exit 1
fi
Expand All @@ -77,18 +77,17 @@ if [ -z "$SCENARIOS" ]; then
fi

if [ -z "$GENERATOR_BINARY" ]; then
echo "Using indexer binary for generator, override with (-g / --generator)."
GENERATOR_BINARY="$INDEXER_BINARY"
echo "path to block-generator binary is required"
exit 1
fi

echo "Running with binary: $INDEXER_BINARY"
echo "Running with binary: $CONDUIT_BINARY"
echo "Report directory: $REPORT_DIR"
echo "Duration: $DURATION"
echo "Log Level: $LOG_LEVEL"

"$GENERATOR_BINARY" \
util block-generator runner \
-i "$INDEXER_BINARY" \
"$GENERATOR_BINARY" runner \
-i "$CONDUIT_BINARY" \
-s "$SCENARIOS" \
-d "$DURATION" \
-c "$CONNECTION_STRING" \
Expand Down
Loading