From 1305a666320d8c77975163472e5bdd470e0aecd5 Mon Sep 17 00:00:00 2001 From: Warren He Date: Wed, 12 Aug 2020 14:46:03 -0700 Subject: [PATCH 1/4] Bump oasis-core version to 20.9 --- Makefile | 2 +- docker/Dockerfile | 2 +- go.mod | 4 ++-- oasis-client/oasis-client.go | 6 +++--- services/block.go | 18 +++++++++--------- services/construction.go | 16 ++++++++-------- tests/construction-txtypes/main.go | 6 +++--- tests/test.sh | 2 ++ 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 6b57ccb9..d30f06df 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ #!/usr/bin/env gmake -OASIS_RELEASE := 20.8.2 +OASIS_RELEASE := 20.9 ROSETTA_CLI_RELEASE := 0.4.0 OASIS_GO ?= go diff --git a/docker/Dockerfile b/docker/Dockerfile index 20c313c0..6a1348c2 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -13,7 +13,7 @@ FROM golang:1.14-alpine AS build # Install prerequisites. RUN rm -f /var/cache/apk/*; apk --no-cache add bash git make gcc g++ libressl-dev libseccomp-dev linux-headers -ARG CORE_BRANCH="v20.8.2" +ARG CORE_BRANCH="v20.9" ARG GATEWAY_BRANCH="master" # Fetch and build oasis-core. diff --git a/go.mod b/go.mod index 3419e5ac..9443f36e 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/coinbase/rosetta-sdk-go v0.3.3 github.com/dgraph-io/badger v1.6.1 github.com/oasisprotocol/ed25519 v0.0.0-20200528083105-55566edd6df0 - github.com/oasisprotocol/oasis-core/go v0.0.0-20200702171459-20d1a2dc6b66 + github.com/oasisprotocol/oasis-core/go v0.20.9 github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1 - google.golang.org/grpc v1.29.1 + google.golang.org/grpc v1.31.0 ) diff --git a/oasis-client/oasis-client.go b/oasis-client/oasis-client.go index f69fcd63..dae65709 100644 --- a/oasis-client/oasis-client.go +++ b/oasis-client/oasis-client.go @@ -52,7 +52,7 @@ type OasisClient interface { GetAccount(ctx context.Context, height int64, owner staking.Address) (*staking.Account, error) // GetStakingEvents returns Oasis staking events at given height. - GetStakingEvents(ctx context.Context, height int64) ([]staking.Event, error) + GetStakingEvents(ctx context.Context, height int64) ([]*staking.Event, error) // SubmitTx submits the given JSON-encoded transaction to the node. SubmitTx(ctx context.Context, txRaw string) error @@ -205,7 +205,7 @@ func (oc *grpcOasisClient) GetAccount(ctx context.Context, height int64, owner s }) } -func (oc *grpcOasisClient) GetStakingEvents(ctx context.Context, height int64) ([]staking.Event, error) { +func (oc *grpcOasisClient) GetStakingEvents(ctx context.Context, height int64) ([]*staking.Event, error) { conn, err := oc.connect(ctx) if err != nil { return nil, err @@ -219,7 +219,7 @@ func (oc *grpcOasisClient) GetStakingEvents(ctx context.Context, height int64) ( var gotBlkHash bool var blkHash []byte for i := range evts { - e := &evts[i] + e := evts[i] if e.TxHash.IsEmpty() { if !gotBlkHash { // First time, need to fetch the block hash. diff --git a/services/block.go b/services/block.go index 9ce6394a..8d82f6e9 100644 --- a/services/block.go +++ b/services/block.go @@ -136,24 +136,24 @@ func (s *blockAPIService) Block( switch { case evt.Transfer != nil: - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(evt.Transfer.From), nil, "-"+evt.Transfer.Tokens.String()) - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(evt.Transfer.To), nil, evt.Transfer.Tokens.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(evt.Transfer.From), nil, "-"+evt.Transfer.Amount.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(evt.Transfer.To), nil, evt.Transfer.Amount.String()) case evt.Burn != nil: - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpBurn, StringFromAddress(evt.Burn.Owner), nil, "-"+evt.Burn.Tokens.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpBurn, StringFromAddress(evt.Burn.Owner), nil, "-"+evt.Burn.Amount.String()) case evt.Escrow != nil: ee := evt.Escrow switch { case ee.Add != nil: // Owner's general account -> escrow account. - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Add.Owner), nil, "-"+ee.Add.Tokens.String()) - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Add.Escrow), &types.SubAccountIdentifier{Address: SubAccountEscrow}, ee.Add.Tokens.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Add.Owner), nil, "-"+ee.Add.Amount.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Add.Escrow), &types.SubAccountIdentifier{Address: SubAccountEscrow}, ee.Add.Amount.String()) case ee.Take != nil: - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Take.Owner), &types.SubAccountIdentifier{Address: SubAccountEscrow}, "-"+ee.Take.Tokens.String()) - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(staking.CommonPoolAddress), nil, ee.Take.Tokens.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Take.Owner), &types.SubAccountIdentifier{Address: SubAccountEscrow}, "-"+ee.Take.Amount.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(staking.CommonPoolAddress), nil, ee.Take.Amount.String()) case ee.Reclaim != nil: // Escrow account -> owner's general account. - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Reclaim.Escrow), &types.SubAccountIdentifier{Address: SubAccountEscrow}, "-"+ee.Reclaim.Tokens.String()) - txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Reclaim.Owner), nil, ee.Reclaim.Tokens.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Reclaim.Escrow), &types.SubAccountIdentifier{Address: SubAccountEscrow}, "-"+ee.Reclaim.Amount.String()) + txns[txidx].Operations = appendOp(txns[txidx].Operations, OpTransfer, StringFromAddress(ee.Reclaim.Owner), nil, ee.Reclaim.Amount.String()) } } } diff --git a/services/construction.go b/services/construction.go index 0392aeb3..ef077074 100644 --- a/services/construction.go +++ b/services/construction.go @@ -406,7 +406,7 @@ func (s *constructionAPIService) ConstructionParse( Address: from, }, Amount: &types.Amount{ - Value: "-" + body.Tokens.String(), + Value: "-" + body.Amount.String(), Currency: OasisCurrency, }, }, @@ -419,7 +419,7 @@ func (s *constructionAPIService) ConstructionParse( Address: StringFromAddress(body.To), }, Amount: &types.Amount{ - Value: body.Tokens.String(), + Value: body.Amount.String(), Currency: OasisCurrency, }, }, @@ -443,7 +443,7 @@ func (s *constructionAPIService) ConstructionParse( Address: from, }, Amount: &types.Amount{ - Value: "-" + body.Tokens.String(), + Value: "-" + body.Amount.String(), Currency: OasisCurrency, }, }, @@ -467,7 +467,7 @@ func (s *constructionAPIService) ConstructionParse( Address: from, }, Amount: &types.Amount{ - Value: "-" + body.Tokens.String(), + Value: "-" + body.Amount.String(), Currency: OasisCurrency, }, }, @@ -483,7 +483,7 @@ func (s *constructionAPIService) ConstructionParse( }, }, Amount: &types.Amount{ - Value: body.Tokens.String(), + Value: body.Amount.String(), Currency: OasisCurrency, }, }, @@ -730,7 +730,7 @@ func (s *constructionAPIService) ConstructionPayloads( body = cbor.Marshal(staking.Transfer{ To: to, - Tokens: *amount, + Amount: *amount, }) case len(remainingOps) == 1 && remainingOps[0].Type == OpBurn && @@ -757,7 +757,7 @@ func (s *constructionAPIService) ConstructionPayloads( } body = cbor.Marshal(staking.Burn{ - Tokens: *amount, + Amount: *amount, }) case len(remainingOps) == 2 && remainingOps[0].Type == OpTransfer && @@ -812,7 +812,7 @@ func (s *constructionAPIService) ConstructionPayloads( body = cbor.Marshal(staking.Escrow{ Account: escrowAccount, - Tokens: *amount, + Amount: *amount, }) // TODO: Devise a way to support reclaim escrow. default: diff --git a/tests/construction-txtypes/main.go b/tests/construction-txtypes/main.go index b4a0570c..e144a8ad 100644 --- a/tests/construction-txtypes/main.go +++ b/tests/construction-txtypes/main.go @@ -95,7 +95,7 @@ func main() { Method: api.MethodTransfer, Body: cbor.Marshal(api.Transfer{ To: dstAddr, - Tokens: *quantity.NewFromUint64(1000), + Amount: *quantity.NewFromUint64(1000), }), } opsBurn := []*types.Operation{ @@ -120,7 +120,7 @@ func main() { Fee: fee100, Method: api.MethodBurn, Body: cbor.Marshal(api.Burn{ - Tokens: *quantity.NewFromUint64(1000), + Amount: *quantity.NewFromUint64(1000), }), } opsAddEscrow := []*types.Operation{ @@ -162,7 +162,7 @@ func main() { Method: api.MethodAddEscrow, Body: cbor.Marshal(api.Escrow{ Account: dstAddr, - Tokens: *quantity.NewFromUint64(1000), + Amount: *quantity.NewFromUint64(1000), }), } diff --git a/tests/test.sh b/tests/test.sh index a071bbbf..19338b36 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -83,6 +83,7 @@ gen_transfer() { local amount=$2 local dst=$3 ${OASIS_NODE} stake account gen_transfer \ + --assume_yes \ --stake.amount $amount \ --stake.transfer.destination "$dst" \ --transaction.file "$tx" \ @@ -100,6 +101,7 @@ gen_burn() { local tx=$1 local amount=$2 ${OASIS_NODE} stake account gen_burn \ + --assume_yes \ --stake.amount $amount \ --transaction.file "$tx" \ --transaction.nonce ${NONCE} \ From 30306b7cc27c9821655ca5e17ffb094e867180fd Mon Sep 17 00:00:00 2001 From: Warren He Date: Thu, 13 Aug 2020 12:10:48 -0700 Subject: [PATCH 2/4] oasis-client: simplify looping --- oasis-client/oasis-client.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/oasis-client/oasis-client.go b/oasis-client/oasis-client.go index dae65709..4c959169 100644 --- a/oasis-client/oasis-client.go +++ b/oasis-client/oasis-client.go @@ -218,8 +218,7 @@ func (oc *grpcOasisClient) GetStakingEvents(ctx context.Context, height int64) ( // Change empty hashes to block hashes, as they belong to block events. var gotBlkHash bool var blkHash []byte - for i := range evts { - e := evts[i] + for _, e := range evts { if e.TxHash.IsEmpty() { if !gotBlkHash { // First time, need to fetch the block hash. From b0cf662d6e70d33f29d9ce2f61277473cdc4d076 Mon Sep 17 00:00:00 2001 From: Warren He Date: Thu, 13 Aug 2020 16:47:59 -0700 Subject: [PATCH 3/4] tests: reduce stats buffering --- tests/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.sh b/tests/test.sh index 19338b36..df5284cd 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -165,7 +165,7 @@ go run ./check-prep # We'll cause a sigpipe on this process, so ignore the exit status. # The downstream awk will exit with nonzero status if this test actually fails without confirming any transactions. ./rosetta-cli --configuration-file rosetta-cli-config.json check:construction || true -} | awk '{ print $0 }; $1 == "[STATS]" && $4 >= 42 { confirmed = 1; exit }; END { exit !confirmed }' +} | stdbuf -oL awk '{ print $0 }; $1 == "[STATS]" && $4 >= 42 { confirmed = 1; exit }; END { exit !confirmed }' rm -rf "${ROOT}/validator-data" /tmp/rosetta-cli* printf "${GRN}### Testing construction signing workflow...${OFF}\n" From c1db72f4c6f899c589a2363795249095ad90968f Mon Sep 17 00:00:00 2001 From: Warren He Date: Mon, 17 Aug 2020 11:45:38 -0700 Subject: [PATCH 4/4] tests: migrate test fixture --- tests/test-fixture-config.json | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test-fixture-config.json b/tests/test-fixture-config.json index e684fb49..7d26038a 100644 --- a/tests/test-fixture-config.json +++ b/tests/test-fixture-config.json @@ -5,9 +5,15 @@ }, "network": { "node_binary": "oasis-node", - "consensus_backend": "", - "consensus_timeout_commit": 1000000000, - "consensus_gas_costs_tx_byte": 0, + "consensus": { + "backend": "", + "params": { + "timeout_commit": 1000000000, + "gas_costs": { + "tx_byte": 0 + } + } + }, "halt_epoch": 18446744073709551615, "epochtime_mock": true, "epochtime_tendermint_interval": 0,