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

Upgrade to latest rosetta sdk #1975

Merged
merged 23 commits into from
May 19, 2021
Merged

Upgrade to latest rosetta sdk #1975

merged 23 commits into from
May 19, 2021

Conversation

xin-hedera
Copy link
Collaborator

@xin-hedera xin-hedera commented May 12, 2021

Detailed description:

  • Upgrade to rosetta-sdk-go v0.6.10 with support of rosetta-specifications@v1.4.10
  • Add construction validation configuration file and test scenario DSL file
  • Build transaction balance-changing operations from both non-fee transfers and crypto transfers
  • Fix /network/options returning all transaction results as successful
  • Fix /construction/preprocess not returning required public keys
  • Fix /construction/parse returning account pubic key instead of account ID
  • Fix /construction/payloads not returning signature type
  • Fix /block returning transactions not after genesis balance timestamp
  • Fix run-validation.sh always install rosetta-cli
  • Upgrade to gorm v1.21.10 (v2) with db connection pool params to fix db connection failure
  • Use First() to get ErrRecordNotFound as it's a gorm v2 breaking change
  • Enable persisting NonFeeTransfers for importer in the all-in-one Dockerfile
  • Add script to retrieve genesis account balances
  • Add construction API validation job to rosetta-api workflow

Which issue(s) this PR fixes:
Fixes #1918

Special notes for your reviewer:
The validate_construction job needs new github secrets to work, before that, it'll fail. The new secrets are:

  • base64 encoded application.yml file with testnet cloud storage credentials
  • base64 encoded json file with two prefunded testnet accounts (account id, private key, and etc)

Checklist

  • Documentation added
  • Tests updated

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
@xin-hedera xin-hedera added enhancement Type: New feature P2 rosetta Area: Rosetta API labels May 12, 2021
@xin-hedera xin-hedera added this to the Mirror 0.34.0 milestone May 12, 2021
@xin-hedera xin-hedera requested a review from a team May 12, 2021 20:23
@xin-hedera xin-hedera self-assigned this May 12, 2021
@codecov
Copy link

codecov bot commented May 12, 2021

Codecov Report

Merging #1975 (4e88b9c) into master (126751e) will decrease coverage by 1.75%.
The diff coverage is 82.88%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1975      +/-   ##
============================================
- Coverage     87.05%   85.30%   -1.76%     
- Complexity     1744     1822      +78     
============================================
  Files           315      277      -38     
  Lines          7731     6300    -1431     
  Branches        740      470     -270     
============================================
- Hits           6730     5374    -1356     
+ Misses          772      682      -90     
- Partials        229      244      +15     
Impacted Files Coverage Δ Complexity Δ
...ra/mirror/monitor/config/MonitorConfiguration.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
.../hedera/mirror/monitor/publish/PublishMetrics.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...a/mirror/monitor/publish/TransactionPublisher.java 1.06% <0.00%> (-0.08%) 1.00 <0.00> (ø)
...a/mirror/monitor/subscribe/AbstractSubscriber.java 77.14% <ø> (-20.00%) 3.00 <0.00> (-1.00)
.../mirror/monitor/subscribe/rest/RestSubscriber.java 100.00% <ø> (ø) 22.00 <0.00> (?)
...nitor/subscribe/rest/RestSubscriberProperties.java 83.33% <ø> (ø) 4.00 <0.00> (?)
hedera-mirror-rosetta/cmd/db.go 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
hedera-mirror-rosetta/tools/maphelper/maphelper.go 100.00% <ø> (ø) 0.00 <0.00> (ø)
...ra/mirror/monitor/subscribe/SubscribeResponse.java 66.66% <66.66%> (ø) 4.00 <4.00> (?)
hedera-mirror-rosetta/cmd/config.go 66.66% <67.74%> (+66.66%) 0.00 <0.00> (ø)
... and 88 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 847069e...4e88b9c. Read the comment docs.

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Looking good on 1st pass, will circle back

Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Some thoughts

- name: Load Docker image
run: |
docker load --input /tmp/test-image.tar
docker image ls -a
Copy link
Contributor

Choose a reason for hiding this comment

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

This also

Suggested change
docker image ls -a

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this step is removed

@@ -41,7 +41,7 @@ func (t *Operation) ToRosetta() *rTypes.Operation {
},
RelatedOperations: []*rTypes.OperationIdentifier{},
Type: t.Type,
Status: t.Status,
Status: &t.Status,
Copy link
Contributor

Choose a reason for hiding this comment

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

q: why the pointer only for Status?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the status changed after transform?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

struct defined by rosetta-sdk-go. it's a breaking change, somewhere in their changelog should have it highlighted as well as the motivation :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, yeah a minor highlight might be useful, thanks

hedera-mirror-rosetta/app/persistence/common/common.go Outdated Show resolved Hide resolved
- fix run-validation always install rosetta-cli

Signed-off-by: Xin Li <xin.li@hedera.com>
- add db pool config

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
Comment on lines 37 to 58
var sqlNamedParamRe = regexp.MustCompile(`(@[^ ,)"'\n]*)`)

// replaces named parameter to indexed format $1, $2, ...
var queryMatcher sqlmock.QueryMatcher = sqlmock.QueryMatcherFunc(func(expectedSQL, actualSQL string) error {
namedParams := sqlNamedParamRe.FindAllString(expectedSQL, -1)

index := 1
namedIndexes := make(map[string]string)
for _, name := range namedParams {
if _, ok := namedIndexes[name]; !ok {
namedIndexes[name] = fmt.Sprintf("$%d", index)
index++
}
}

for name, indexStr := range namedIndexes {
expectedSQL = strings.ReplaceAll(expectedSQL, name, indexStr)
}

return sqlmock.QueryMatcherRegexp.Match(regexp.QuoteMeta(expectedSQL), actualSQL)
})

Copy link
Collaborator Author

@xin-hedera xin-hedera May 18, 2021

Choose a reason for hiding this comment

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

gorm v2 no longer supports postgresql index style param placeholder as the input SQL query. All the raw queries are converted to gorm v2's named param style (starts with @).

gorm v2 translates the SQL query's named param to index style placeholder (since gorm is configured with postgresql dialect) before it's captured by the mock.

the queryMatcher does the same translation so in our tests we can pass the SQL query and its param values match.

we really should test against real db instead.


if (./rosetta-cli 2>&1 | grep -q 'CLI for the Rosetta API'); then
if (./rosetta-cli 2>&1 | grep 'CLI for the Rosetta API' > /dev/null); then
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

grep -q with the pipe and set -o pipefail will cause error code 141 since grep -q exits once a match is found, without consuming all the data from the pipe, thus rosetta-cli is always being installed.

Comment on lines +15 to +28
with genesis_balance as (
select account_id, balance
from ((select min(consensus_timestamp) as timestamp from account_balance_file)) as genesis
join crypto_transfer ct
on ct.consensus_timestamp > genesis.timestamp
join account_balance ab
on ab.account_id = ct.entity_id and ab.consensus_timestamp = genesis.timestamp
where balance <> 0
group by account_id,balance
order by min(ct.consensus_timestamp)
limit 20
)
select json_agg(json_build_object('id', account_id::text, 'value', balance::text))
from genesis_balance
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the query selects up to 20 accounts' genesis balance. the accounts are ordered by their first crypto transfer after the genesis balance timestamp

needs the CTE otherwise the json_agg will repeat every account & balance pair for the number of occurencies as if there is no group by

# Enable persisting non-fee transfers to reconstruct the original transfer list
ENV HEDERA_MIRROR_IMPORTER_PARSER_RECORD_ENTITY_PERSIST_NONFEETRANSFERS=true
# Disable Redis because gRPC process is not run within this execution
ENV HEDERA_MIRROR_IMPORTER_PARSER_RECORD_ENTITY_REDIS_ENABLED=false
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is moved from run_supervisord.sh

Comment on lines +59 to +74
// selectGenesis - Selects the first block whose consensus_end is after the genesis account balance
// timestamp. Return the record file with adjusted consensus start
selectGenesis string = `SELECT
consensus_end,
hash,
index,
prev_hash,
CASE
WHEN genesis.min >= rf.consensus_start THEN genesis.min + 1
ELSE rf.consensus_start
END AS consensus_start
FROM record_file AS rf
JOIN (SELECT MIN(consensus_timestamp) FROM account_balance_file) AS genesis
ON consensus_end > genesis.min
ORDER BY consensus_end
LIMIT 1`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The query finds the genesis record file and adjusts its consensus start to make sure that consensus start > first ingested account balance file consensus timestamp

index += br.genesisRecordFileIndex
if index == br.genesisRecordFileIndex {
rf = br.genesisRecordFile
} else if err := br.dbClient.Raw(selectRecordFileByIndex, sql.Named("index", index)).First(rf).Error; err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

gorm v2's breaking change: only First, Last, and Take return ErrRecordNotFound

Comment on lines +92 to +93
echo "Installing Rosetta CLI"
curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s -- -b .
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

install rosetta-cli before running the scripts otherwise the two processes may run into race condition

Signed-off-by: Xin Li <xin.li@hedera.com>
- refactor errors
- increase validation timeout to 20 mins

Signed-off-by: Xin Li <xin.li@hedera.com>
Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

Looks good, one nit suggestion

`hedera.mirror.rosetta.db.host` | 127.0.0.1 | The IP or hostname used to connect to the database
`hedera.mirror.rosetta.db.name` | mirror_node | The name of the database
`hedera.mirror.rosetta.db.password` | mirror_rosetta_pass | The database password the processor uses to connect.
`hedera.mirror.rosetta.db.password` | mirror_rosetta_pass | The database password the processor uses to connect
`hedera.mirror.rosetta.db.pool.maxIdleConns` | 20 | The maximum number of idle database connections
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would prefer the full Connections vs Conns here and below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

Signed-off-by: Xin Li <xin.li@hedera.com>
@sonarcloud
Copy link

sonarcloud bot commented May 19, 2021

@xin-hedera xin-hedera requested a review from Nana-EC May 19, 2021 16:14
Copy link
Contributor

@Nana-EC Nana-EC left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@steven-sheehy steven-sheehy left a comment

Choose a reason for hiding this comment

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

LGTM

@xin-hedera xin-hedera merged commit 1307d96 into master May 19, 2021
@xin-hedera xin-hedera deleted the latest-rosetta-sdk branch May 19, 2021 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature P2 rosetta Area: Rosetta API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade to latest Rosetta SDK
3 participants