CityOfZion / neo-local

Personal blockchain for NEO dApp development!
MIT License
52 stars 26 forks source link

Add MIN_BLOCK to .env #153

Closed archaengel closed 5 years ago

archaengel commented 5 years ago

Problem

neo-local-faucet service fails to process request from any wallet with default env variable BOOTSTRAP=_4kBlocks. Chain height of < 5000 breaks service and cause infinite loop in container. ...

Solution

Add MIN_BLOCK=2500 to .env file ...

Checklist

nunojusto commented 5 years ago

I cannot replicate the problem you say. You ned to wait a bit to neo-faucet get synced to the current block, but after it's all OK. See attach screenshot.

image

archaengel commented 5 years ago

My apologies, I may have described the issue poorly.

The faucet status check passes, but submitting a request to the wallet (on the develop branch) fails for me on my local system and in a clean EC2 instance.

In the neo-local-faucet repo, in the checkAddress function,

while (!found && currentIteratedBlock > maxBlock){..}

is used to check that the last transaction from the faucet was recorded on the chain at some time before a given number of blocks ago. This number of blocks is the value of MIN_BLOCK variable, which defaults to 5000 in line 5 of the server's variables file as the minBlocks var imported in the check address file.

At the bottom of the loop, currentIteratedBlock is set to the block height of the last transaction sent from the faucet wallet.

The value of maxBlock will be negative if the height of the chain is lower than the value of minBlocks;

 const {
      data: { height }
    } = await get(`${neoscanAddress}/v1/get_height`);
const maxBlock = height - minBlocks;

so !found && currentIteratedBlock > maxBlock always evaluates to true.

checkAddress then gets imported into the faucet request endpoint which is hit when a user clicks the request button on the address form.

I fear I now may have over-explained/over-complicated, so apologies for that, as well. :stuck_out_tongue:

I've attached a gist below with what I believe are relevant parts of code, along with the original files, and screenshots.

Thanks for taking the time to look this all over, by the way.


nunojusto commented 5 years ago

Ok, I understood. We can have here two solutions: 1- Produce new images with more than 5k blocks and add that option to neo-local as a selector of chain 2- Override the neo-local-faucet with env vars

And I like the first version, because it's more clean, without env vars doing the hack. I will produce a new chain and commit the change. Thanks @archaengel. Very nice investigation.

archaengel commented 5 years ago

Much cleaner, indeed.

The first tx from the faucet address occurs at a height around 1300, so the chain will have to be ~6300 blocks tall before a request will make it through, just to help stem any headaches on your end.

It was a pleasure, thank you for the review 👍