How do you analyse the block after the fact? I mean what tools do you use etc.
It's more of a process, rather than a tool.
E.g. for #477115
My node informed be that it rejected the block with a message like this:
AcceptBlock: Unknown input TxID: 9639dd073e67efc879abb1075fafa4fa23d5fa427c129b2b1dd4f5a5520b408d
Looking into the code of the node, I see that this basically means that the block was trying to spend an input from an "non-existing" transaction (its ID is printed)
So I save the block on a disk in a separate file and then use a code like this:
package main
import (
"fmt"
"io/ioutil"
"github.com/piotrnar/gocoin/lib/btc"
)
func main() {
d, _ := ioutil.ReadFile("477115-0000000000000000013ee4a86822d37a061732e04ee5f41fb77168f193363d1b.bin")
println(d)
bl, _ := btc.NewBlock(d)
println(bl)
bl.BuildTxList()
println(len(bl.Txs))
for i, tx := range bl.Txs {
fmt.Println(i, tx.Hash.String())
for ii, inp := range tx.TxIn {
fmt.Println(" ", ii, inp.Input.String())
}
}
}
... it will print all the TxID inside the block, as well as the inputs they are spending:
https://pastebin.com/LtMKi8pCBrowsing the results for the problematic TxID (9639dd073e67efc879abb1075fafa4fa23d5fa427c129b2b1dd4f5a5520b408d), I see it in two places:
22 7a122ef22468e4af16b010d7acf7aa81e5af3636423c613fd98246c179d79800
0 9639dd073e67efc879abb1075fafa4fa23d5fa427c129b2b1dd4f5a5520b408d-001
[...]
90 9639dd073e67efc879abb1075fafa4fa23d5fa427c129b2b1dd4f5a5520b408d
0 796c96815be92f9351cbdd0cb52df426d4af18504a3734a3a4a8f5352555c4f2-000
This means that tx number 22 was trying to spend output from tx number 90.
Meaning: invalid block.
As for the other block (#474294)
Looking for the missing tx (b11a78c6c61af1cb37586f639050d74b95c2b0fd525623b6cb6a4bb4fba46a0e), you don't find it inside the invalid block.
So you go to blockchain.info and look for it:
https://blockchain.info/tx/b11a78c6c61af1cb37586f639050d74b95c2b0fd525623b6cb6a4bb4fba46a0eThere you see that it was confirmed in (alternative) block #474294.
Which gets you to the conclusion that if (any) block #474294 was trying to spend it, while not including it, it obviously is the reason for it to be invalid.