Skip to content
Snippets Groups Projects
Commit 90b697b3 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Rewind rolls your local idea of the chain back a few blocks and tries to...

Rewind rolls your local idea of the chain back a few blocks and tries to resynchronize. This can be good if you think you are stuck.
parent 179b6a72
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi
source ${BFAHOME}/bin/libbfa.sh || exit 1
geth_exec_js ${BFAHOME}/src/js.rewind
// vim:syntax:filetype=javascript:ai:sm
// vim:expandtab:backspace=indent,eol,start:softtabstop=4
// How many blocks to step back.
var backstep = 6
// If we are syncing, there's no need to rewind (I think?)
if (!eth.syncing && eth.blockNumber > 10)
{
var max = 0
// Get the maximum difficulty of all valid connected peers
for (x in admin.peers)
{
var xd = admin.peers[x].protocols.eth.difficulty
if (admin.peers[x].protocols.eth!="handshake" && xd>max)
max=xd
}
if (eth.blockNumber.totalDifficulty+200<max) {
console.log(
"Max total difficulty is "
+ max
+ ", but mine is just "
+ eth.blockNumber.totalDifficulty
+ " (in block "
+ eth.blockNumber
+ "). Rolling "
+ backstep+" blocks back, to block "
+ web3.toHex(eth.blockNumber-backstep)
)
// Rollback a bit and see if we weren't stuck just because we were stuck in a side fork.
debug.setHead(web3.toHex(eth.blockNumber-backstep))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment