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

Workaround the missing disappearing token transfer issue #3289

Merged
merged 12 commits into from Feb 16, 2022

Conversation

xin-hedera
Copy link
Collaborator

@xin-hedera xin-hedera commented Feb 11, 2022

Description:

  • Add workaround for the missing disappearing token transfer issue
  • Improve nft balance tracking performance
  • Only show token related data for tokens created after genesis timestmap
  • Update rosetta-cli check:data configuration to sync from index 1
  • Remove genesis token balance retrieval logic in get-genesis-balance.sh
  • Update rosetta github workflow to not generate genesis balance JSON file
  • Fix bug that importer start date can't be changed
  • Enable supervisorctl
  • Fix issue that the supervisord process doesn't get SIGTERM sent by docker stop
  • Set stopwaitsecs for importer and postgres for graceful shutdown
  • Update postgres config for normal operation

Related issue(s):

Fixes #

Notes for reviewer:

Note the failing check:construction in our workflow is due to the STARTDATE env in supervisord.conf set to epoch and can't be overridden, so importer always syncs from testnet genesis.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

…e after the token is deleted

Signed-off-by: Xin Li <xin.li@hedera.com>
@xin-hedera xin-hedera self-assigned this Feb 11, 2022
@xin-hedera xin-hedera added rosetta Area: Rosetta API P1 labels Feb 11, 2022
Comment on lines -155 to -157
- name: Get Genesis Account Balances
run: ./scripts/validation/get-genesis-balance.sh testnet

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

applied the logic to check:data from block 1 so no longer needs the genesis balance JSON file

@codecov
Copy link

codecov bot commented Feb 11, 2022

Codecov Report

Merging #3289 (0105c06) into main (70a9cb4) will decrease coverage by 19.60%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##               main    #3289       +/-   ##
=============================================
- Coverage     88.17%   68.56%   -19.61%     
+ Complexity     2508      845     -1663     
=============================================
  Files           502      161      -341     
  Lines         14143     2761    -11382     
  Branches       1306      159     -1147     
=============================================
- Hits          12470     1893    -10577     
+ Misses         1365      804      -561     
+ Partials        308       64      -244     
Impacted Files Coverage Δ
hedera-mirror-rosetta/app/persistence/account.go
hedera-mirror-rosetta/app/persistence/block.go
...ra-mirror-rosetta/app/persistence/domain/entity.go
...dera-mirror-rosetta/app/persistence/transaction.go
...era-mirror-rosetta/app/services/account_service.go
errors/dbError.js
...a/mirror/grpc/listener/NotifyingTopicListener.java
...mporter/downloader/CommonDownloaderProperties.java
model/customFee.js
viewmodel/nftTransferViewModel.js
... and 333 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 70a9cb4...0105c06. Read the comment docs.

Comment on lines +70 to +86
), '[]') as token_values,
(
select coalesce(json_agg(json_build_object(
'associated', associated,
'decimals', decimals,
'token_id', token_id,
'type', type
) order by token_id), '[]')
from (
select distinct on (t.token_id) ta.associated, t.decimals, t.token_id, t.type
from token_account ta
join token t on t.token_id = ta.token_id
join genesis on t.created_timestamp > genesis.timestamp
where account_id = @account_id and ta.modified_timestamp <= @end
order by t.token_id, ta.modified_timestamp desc
) as associations
) as token_associations`
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

get the latest state of the token associations for an account X <= consensus timestamp T for tokens created after genesis timestamp

@steven-sheehy steven-sheehy added this to the 0.51.0 milestone Feb 11, 2022
Comment on lines 533 to 541
for _, txn := range transactions {
if txn.Type == transactionTypeTokenDissociate && IsTransactionResultSuccessful(int32(txn.Result)) {
hasSuccessTokenDissociate = true
break
}
}
if !hasSuccessTokenDissociate {
return 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.

don't even run the SQL query if there's no successful token dissociate.

Comment on lines +16 to +19
"historical_balance_enabled": true,
"inactive_discrepancy_search_disabled": false,
"reconciliation_disabled": false,
"start_index": 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.

with this config, check:data no longer needs the bootstrap genesis balances JSON file, nor the made up genesis block.

tb.account_id in (:account_ids) and
balance <> 0
EOF
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there won't be token balances at genesis with the changes in go code

@xin-hedera xin-hedera requested a review from a team February 11, 2022 21:10
@steven-sheehy steven-sheehy added the bug Type: Something isn't working label Feb 14, 2022
Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
…ostgres parrams

Signed-off-by: Xin Li <xin.li@hedera.com>
@xin-hedera xin-hedera force-pushed the missing-disappearing-token-transfer-workaround branch from 3f36a7b to 16d729d Compare February 16, 2022 02:49
…ervisord

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Xin Li <xin.li@hedera.com>
@xin-hedera xin-hedera marked this pull request as ready for review February 16, 2022 15:48
Comment on lines +587 to +602
accountIds := make([]int64, 0)
for _, transfer := range cryptoTransfers {
key := transfer.AccountId.EncodedId
cryptoTransferMap[key] = hbarTransfer{
accountId := transfer.AccountId.EncodedId
if _, ok := cryptoTransferMap[accountId]; !ok {
accountIds = append(accountIds, accountId)
}
cryptoTransferMap[accountId] = hbarTransfer{
AccountId: transfer.AccountId,
Amount: transfer.Amount + cryptoTransferMap[key].Amount,
Amount: transfer.Amount + cryptoTransferMap[accountId].Amount,
}
}

adjusted := make([]hbarTransfer, 0, len(cryptoTransfers))
for key, aggregated := range cryptoTransferMap {
amount := aggregated.Amount - nonFeeTransferMap[key]
for _, accountId := range accountIds {
aggregated := cryptoTransferMap[accountId]
amount := aggregated.Amount - nonFeeTransferMap[accountId]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

make the crypto transfers in a consistent order

) (*rTypes.AccountCoinsResponse, *rTypes.Error) {
return nil, errors.ErrNotImplemented
}

// getAdditionalTokenBalances get the additional token balances with 0 amount for tokens the account has ever owned by
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no longer needed since now AccountRepository.RetrieveBalanceAtBlock also handles the ever owned tokens and returns 0 amount for those tokens in a single call

listen_addresses = '*'
log_checkpoints = on
max_connections = 200
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 default max connections in rosetta config is 100, the default of pg server is 100. under load, quite some queries can fail since the db server refuses to open more connections for rosetta server as certain ratio of the server's max connections are reserved for superuser

@@ -3,12 +3,12 @@ set -eo pipefail

function run_offline_mode() {
echo "Running in offline mode"
supervisord --configuration /app/supervisord-offline.conf
exec supervisord --configuration /app/supervisord-offline.conf
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

with exec, the supervisord process can receive signals, so we can do docker stop -t 90 <container_id> to gracefully shutdown the services

Comment on lines 12 to 17
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

complete the config to enable supervisorctl which works similarly as systemctl

@@ -17,5 +23,4 @@ autorestart=true
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stopsignal=SIGTERM
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

SIGTERM is the default stopsignal supervisord sends

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

@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.

Nice work, some q's and suggestions on 1st
Still digging into test side

hedera-mirror-rosetta/app/persistence/common.go Outdated Show resolved Hide resolved
hedera-mirror-rosetta/app/persistence/domain/entity.go Outdated Show resolved Hide resolved
docs/rosetta/README.md Show resolved Hide resolved
docs/rosetta/README.md Show resolved Hide resolved
hedera-mirror-rosetta/app/persistence/account.go Outdated Show resolved Hide resolved
hedera-mirror-rosetta/app/persistence/transaction.go Outdated Show resolved Hide resolved
steven-sheehy
steven-sheehy previously approved these changes Feb 16, 2022
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! Great work on this

Signed-off-by: Xin Li <xin.li@hedera.com>
steven-sheehy
steven-sheehy previously approved these changes Feb 16, 2022
Signed-off-by: Xin Li <xin.li@hedera.com>
Nana-EC
Nana-EC previously approved these changes Feb 16, 2022
Copy link
Collaborator

@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

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

sonarcloud bot commented Feb 16, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
9.2% 9.2% Duplication

@xin-hedera xin-hedera merged commit 903df34 into main Feb 16, 2022
@xin-hedera xin-hedera deleted the missing-disappearing-token-transfer-workaround branch February 16, 2022 19:27
xin-hedera added a commit that referenced this pull request Feb 16, 2022
- Add workaround for the missing disappearing token transfer issue
- Improve nft balance tracking performance
- Only show token related data for tokens created after genesis timestmap
- Update rosetta-cli check:data configuration to sync from index 1
- Remove genesis token balance retrieval logic in get-genesis-balance.sh
- Update rosetta github workflow to not generate genesis balance JSON file
- Fix bug that importer start date can't be changed
- Enable supervisorctl
- Fix issue that the supervisord process doesn't get SIGTERM sent by docker stop
- Set stopwaitsecs for importer and postgres for graceful shutdown
- Update postgres config for normal operation

Signed-off-by: Xin Li <xin.li@hedera.com>
@steven-sheehy steven-sheehy linked an issue Feb 16, 2022 that may be closed by this pull request
matheus-dallrosa pushed a commit that referenced this pull request Feb 18, 2022
- Add workaround for the missing disappearing token transfer issue
- Improve nft balance tracking performance
- Only show token related data for tokens created after genesis timestmap
- Update rosetta-cli check:data configuration to sync from index 1
- Remove genesis token balance retrieval logic in get-genesis-balance.sh
- Update rosetta github workflow to not generate genesis balance JSON file
- Fix bug that importer start date can't be changed
- Enable supervisorctl
- Fix issue that the supervisord process doesn't get SIGTERM sent by docker stop
- Set stopwaitsecs for importer and postgres for graceful shutdown
- Update postgres config for normal operation

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Matheus DallRosa <matheus.dallrosa@swirlds.com>
matheus-dallrosa pushed a commit that referenced this pull request Feb 21, 2022
- Add workaround for the missing disappearing token transfer issue
- Improve nft balance tracking performance
- Only show token related data for tokens created after genesis timestmap
- Update rosetta-cli check:data configuration to sync from index 1
- Remove genesis token balance retrieval logic in get-genesis-balance.sh
- Update rosetta github workflow to not generate genesis balance JSON file
- Fix bug that importer start date can't be changed
- Enable supervisorctl
- Fix issue that the supervisord process doesn't get SIGTERM sent by docker stop
- Set stopwaitsecs for importer and postgres for graceful shutdown
- Update postgres config for normal operation

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Matheus DallRosa <matheus.dallrosa@swirlds.com>
matheus-dallrosa pushed a commit that referenced this pull request Feb 21, 2022
- Add workaround for the missing disappearing token transfer issue
- Improve nft balance tracking performance
- Only show token related data for tokens created after genesis timestmap
- Update rosetta-cli check:data configuration to sync from index 1
- Remove genesis token balance retrieval logic in get-genesis-balance.sh
- Update rosetta github workflow to not generate genesis balance JSON file
- Fix bug that importer start date can't be changed
- Enable supervisorctl
- Fix issue that the supervisord process doesn't get SIGTERM sent by docker stop
- Set stopwaitsecs for importer and postgres for graceful shutdown
- Update postgres config for normal operation

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Matheus DallRosa <matheus.dallrosa@swirlds.com>
matheus-dallrosa pushed a commit that referenced this pull request Feb 22, 2022
- Add workaround for the missing disappearing token transfer issue
- Improve nft balance tracking performance
- Only show token related data for tokens created after genesis timestmap
- Update rosetta-cli check:data configuration to sync from index 1
- Remove genesis token balance retrieval logic in get-genesis-balance.sh
- Update rosetta github workflow to not generate genesis balance JSON file
- Fix bug that importer start date can't be changed
- Enable supervisorctl
- Fix issue that the supervisord process doesn't get SIGTERM sent by docker stop
- Set stopwaitsecs for importer and postgres for graceful shutdown
- Update postgres config for normal operation

Signed-off-by: Xin Li <xin.li@hedera.com>
Signed-off-by: Matheus DallRosa <matheus.dallrosa@swirlds.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Type: Something isn't working P1 rosetta Area: Rosetta API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rosetta reconciliation performance
3 participants