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

Not possible to import BNS data without first syncing #1327

Closed
wileyj opened this issue Sep 21, 2022 · 3 comments
Closed

Not possible to import BNS data without first syncing #1327

wileyj opened this issue Sep 21, 2022 · 3 comments
Assignees

Comments

@wileyj
Copy link
Contributor

wileyj commented Sep 21, 2022

From conversation with @rafaelcr and related issue: stacks-network/stacks-blockchain-docker#90

With the release of v5.0.0, BNS_IMPORT_DIR is no longer used during starting the API normally.
In previous versions of the API, with this env var defined - the API would process the BNS data and add DB records.

In v5.0.0, i understand this work is being offloaded to the event-replay function. In my testing, i noticed that starting the API normally alongside postgres and a stacks-blockchain node (with STACKS_EXPORT_EVENTS_FILE defined) works as expected and the tsv file is populated with blocks.
Stopping the API after a few blocks, then running the event-replay allows the BNS data to be imported normally.

What doesn't work (and i think this would be the use case for most people) is importing BNS data before running the API normally (i.e. syncing from genesis).

  1. if you haven't started the API, no tsv file exists and the import-events function will fail on file not found (expected)
  2. using an empty tsv file gets past the previous error, and i was expecting the BNS import to proceed but it does not:
{12:07}~/Git/blockstack/public/stacks-blockchain-api:master ✗ ➭ touch file.tsv
node ./lib/index.js import-events \
    --file file.tsv --wipe-db --force
{"level":"info","message":"Shutting down... received beforeExit.","timestamp":"2022-09-21T16:07:44.961Z"}
{"level":"info","message":"App shutdown successful.","timestamp":"2022-09-21T16:07:44.963Z"}

tl;dr - it's not possible to import BNS data until you've started the API normally and synced a few blocks. I believe it should be possible via cmd-line switch or natively to import this BNS data before you start syncing the API.

@blockstack-devops blockstack-devops moved this to Recent issues in API Board Sep 21, 2022
@zone117x
Copy link
Member

Makes sense.

One of the reasons for this change was to get the genesis block info required for correctly importing BNS, which we can't know if importing from scratch.

We still have the config_state table with some global singleton values in order to track state like this.

Perhaps we could add a new field like bns_import_needs_genesis: boolean, which we could use to first import BNS data with empty genesis block info (setting bns_import_needs_genesis=true), then on genesis block receipt, we can check bns_import_needs_genesis to determine if the "partially" inserted BNS data needs a giant UPDATE.

@rafaelcr thoughts?

@rafaelcr
Copy link
Collaborator

That's a good idea @zone117x ... we should aim for a solution that works both for event replay and genesis sync, and this sounds like it could fit the bill.

@saralab saralab moved this from Recent issues to Backlog in API Board Sep 27, 2022
@rafaelcr rafaelcr moved this from Backlog to In Development in API Board Oct 10, 2022
@saralab saralab assigned BLuEScioN and unassigned rafaelcr Nov 8, 2022
@rafaelcr
Copy link
Collaborator

Fixed in #1441

Repository owner moved this from In Development to Done in API Board Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

4 participants