Closed ericpassmore closed 1 year ago
get_block_header_state
can only return reversible blocks. While in your curl examples you do request the sole reversible block, it's not clear how back-to-back you made those requests: with a single producer a block becomes irreversible in 500ms, so there is only a valid block this endpoint can be used with for 500ms
Can you try something like
curl -d "{\"block_num_or_id\":$(curl -s http://127.0.0.1:8888/v1/chain/get_info | jq .fork_db_head_block_num)}" http://127.0.0.1:8888/v1/chain/get_block_header_state
This makes the request back-to-back so there is a higher (but not 100%) chance of success.
Yep, the back to back requests worked on the command line.
When I run test for eosjs
it still fails. The calls are one after another, but there is too much lag between the calls.
I recompiling with an increased block time of 2000ms, by updating libraries/chain/include/eosio/chain/config.hpp
. That didn't work. It failed 33 tests, and once the chain was running I found it was still going producing blocks very quickly.
I'm guessing the only option is to speed up the eosjs
code, to be as fast as possible.
If you need to keep using get_block_header_state
(without knowing more details about the test it's difficult for me to know if there is a better alternative), one fairly easy workaround here is to simply run multiple producers. Running even 3 or 4 producers will increase the reversible time to many seconds. You can run multiple producers with a single node instance, you'd just
producer-name = eosio
producer-name = rick
producer-name = morty
producer-name = summer
or such.
The slightly more difficult part is you'll need to set the old bios contract so you can setprods
the new producer schedule.
You'll need to do something like
cleos create account eosio rick EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio morty EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
cleos create account eosio summer EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
Then install the old bios contract
cleos set contract eosio libraries/testing/contracts/old_versions/v1.6.0-rc3/eosio.bios
Then create a prods.json
file like
{
"schedule": [
{"producer_name":"eosio","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"},
{"producer_name":"rick","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"},
{"producer_name":"morty","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"},
{"producer_name":"summer","block_signing_key":"EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"}
]
}
Then setprods
cleos push action eosio setprods "$(cat prods.json)" -p eosio@active
Now you should have a 4 producer chain thus a lot more leeway to call get_block_header_state
Thanks, I did get the code to work, at the expense of a extra get_block_header_state
call for send_transaction2
. I'm closing this issue as not planned.
In eosjs, the refBlock
from get_block_header_state
is used to calculate and expiration and a prefix used in the transaction header. I feel comfortable calculating an expiration time without the refBlock
timestamp. I don't understand what the prefix
is or how it is used. Something to look into later.
/** TAPoS: Return transaction fields which reference `refBlock` and expire `expireSeconds` after `timestamp` */
export function transactionHeader(refBlock: BlockTaposInfo, expireSeconds: number) {
const timestamp = refBlock.header ? refBlock.header.timestamp : refBlock.timestamp;
const prefix = parseInt(reverseHex(refBlock.id.substring(16, 24)), 16);
return {
expiration: timePointSecToDate(dateToTimePointSec(timestamp) + expireSeconds),
ref_block_num: refBlock.block_num & 0xffff,
ref_block_prefix: prefix,
};
}
When running on a local hosted single producer node, the called to
get_block_header_state
never works. Want to get this working so I can run tests on my local nodeos.Example Curl Requests
Config