trying to get witness coinbases to validate
(they don't)
This commit is contained in:
parent
7fdcf9bfbc
commit
ee4dd8aaa0
8
shell.go
8
shell.go
@ -69,10 +69,10 @@ func shell() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// once we're connected, initiate headers sync
|
// once we're connected, initiate headers sync
|
||||||
err = SCon.AskForHeaders()
|
// err = SCon.AskForHeaders()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
log.Fatal(err)
|
// log.Fatal(err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
// main shell loop
|
// main shell loop
|
||||||
for {
|
for {
|
||||||
|
@ -118,7 +118,8 @@ func (s *SPVCon) IngestMerkleBlock(m *wire.MsgMerkleBlock) {
|
|||||||
if !hah.blockhash.IsEqual(&newMerkBlockSha) {
|
if !hah.blockhash.IsEqual(&newMerkBlockSha) {
|
||||||
log.Printf("merkle block out of order got %s expect %s",
|
log.Printf("merkle block out of order got %s expect %s",
|
||||||
m.Header.BlockSha().String(), hah.blockhash.String())
|
m.Header.BlockSha().String(), hah.blockhash.String())
|
||||||
log.Printf("has %d hashes", len(m.Hashes))
|
log.Printf("has %d hashes %d txs flags: %x",
|
||||||
|
len(m.Hashes), m.Transactions, m.Flags)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,6 +284,40 @@ func (s *SPVCon) AskForHeaders() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AskForOneBlock is for testing only, so you can ask for a specific block height
|
||||||
|
// and see what goes wrong
|
||||||
|
func (s *SPVCon) AskForOneBlock(h int32) error {
|
||||||
|
var hdr wire.BlockHeader
|
||||||
|
var err error
|
||||||
|
|
||||||
|
dbTip := int32(h)
|
||||||
|
s.headerMutex.Lock() // seek to header we need
|
||||||
|
_, err = s.headerFile.Seek(int64((dbTip)*80), os.SEEK_SET)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = hdr.Deserialize(s.headerFile) // read header, done w/ file for now
|
||||||
|
s.headerMutex.Unlock() // unlock after reading 1 header
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("header deserialize error!\n")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
bHash := hdr.BlockSha()
|
||||||
|
// create inventory we're asking for
|
||||||
|
iv1 := wire.NewInvVect(wire.InvTypeWitnessBlock, &bHash)
|
||||||
|
gdataMsg := wire.NewMsgGetData()
|
||||||
|
// add inventory
|
||||||
|
err = gdataMsg.AddInvVect(iv1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
hah := NewRootAndHeight(bHash, h)
|
||||||
|
s.outMsgQueue <- gdataMsg
|
||||||
|
s.blockQueue <- hah // push height and mroot of requested block on queue
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// AskForMerkBlocks requests blocks from current to last
|
// AskForMerkBlocks requests blocks from current to last
|
||||||
// right now this asks for 1 block per getData message.
|
// right now this asks for 1 block per getData message.
|
||||||
// Maybe it's faster to ask for many in a each message?
|
// Maybe it's faster to ask for many in a each message?
|
||||||
@ -347,9 +382,9 @@ func (s *SPVCon) AskForBlocks() error {
|
|||||||
iv1 := new(wire.InvVect)
|
iv1 := new(wire.InvVect)
|
||||||
// if hardmode, ask for legit blocks, none of this ralphy stuff
|
// if hardmode, ask for legit blocks, none of this ralphy stuff
|
||||||
if s.HardMode {
|
if s.HardMode {
|
||||||
iv1 = wire.NewInvVect(wire.InvTypeBlock, &bHash)
|
iv1 = wire.NewInvVect(wire.InvTypeWitnessBlock, &bHash)
|
||||||
} else { // ah well
|
} else { // ah well
|
||||||
iv1 = wire.NewInvVect(wire.InvTypeFilteredBlock, &bHash)
|
iv1 = wire.NewInvVect(wire.InvTypeFilteredWitnessBlock, &bHash)
|
||||||
}
|
}
|
||||||
gdataMsg := wire.NewMsgGetData()
|
gdataMsg := wire.NewMsgGetData()
|
||||||
// add inventory
|
// add inventory
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package uspv
|
package uspv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
@ -24,6 +24,8 @@ func BlockRootOK(blk wire.MsgBlock) bool {
|
|||||||
for len(shas) > 1 { // calculate merkle root. Terse, eh?
|
for len(shas) > 1 { // calculate merkle root. Terse, eh?
|
||||||
shas = append(shas[2:], MakeMerkleParent(shas[0], shas[1]))
|
shas = append(shas[2:], MakeMerkleParent(shas[0], shas[1]))
|
||||||
} // auto recognizes coinbase-only blocks
|
} // auto recognizes coinbase-only blocks
|
||||||
|
fmt.Printf("MRs calcd %s given %s\n",
|
||||||
|
shas[0].String(), blk.Header.MerkleRoot.String())
|
||||||
return blk.Header.MerkleRoot.IsEqual(shas[0])
|
return blk.Header.MerkleRoot.IsEqual(shas[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +33,16 @@ func BlockRootOK(blk wire.MsgBlock) bool {
|
|||||||
// different enough that it's better to have 2 separate functions
|
// different enough that it's better to have 2 separate functions
|
||||||
func (s *SPVCon) IngestBlock(m *wire.MsgBlock) {
|
func (s *SPVCon) IngestBlock(m *wire.MsgBlock) {
|
||||||
var err error
|
var err error
|
||||||
|
var buf bytes.Buffer
|
||||||
|
m.SerializeWitness(&buf)
|
||||||
|
fmt.Printf("block hex %x\n", buf.Bytes())
|
||||||
|
for i, tx := range m.Transactions {
|
||||||
|
// if i > 0 {
|
||||||
|
fmt.Printf("wtxid: %s\n", tx.WTxSha())
|
||||||
|
fmt.Printf("txid: %s\n", tx.TxSha())
|
||||||
|
fmt.Printf("%d %s", i, TxToString(tx))
|
||||||
|
// }
|
||||||
|
}
|
||||||
ok := BlockRootOK(*m) // check block self-consistency
|
ok := BlockRootOK(*m) // check block self-consistency
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Printf("block %s not OK!!11\n", m.BlockSha().String())
|
fmt.Printf("block %s not OK!!11\n", m.BlockSha().String())
|
||||||
@ -59,7 +70,6 @@ func (s *SPVCon) IngestBlock(m *wire.MsgBlock) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(len(m.Transactions))
|
wg.Add(len(m.Transactions))
|
||||||
for i, tx := range m.Transactions {
|
for i, tx := range m.Transactions {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
hits, err := s.TS.Ingest(tx, hah.height)
|
hits, err := s.TS.Ingest(tx, hah.height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -99,35 +109,3 @@ func (s *SPVCon) IngestBlock(m *wire.MsgBlock) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SPVCon) AskForOneBlock(h int32) error {
|
|
||||||
var hdr wire.BlockHeader
|
|
||||||
var err error
|
|
||||||
|
|
||||||
dbTip := int32(h)
|
|
||||||
s.headerMutex.Lock() // seek to header we need
|
|
||||||
_, err = s.headerFile.Seek(int64((dbTip)*80), os.SEEK_SET)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = hdr.Deserialize(s.headerFile) // read header, done w/ file for now
|
|
||||||
s.headerMutex.Unlock() // unlock after reading 1 header
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("header deserialize error!\n")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
bHash := hdr.BlockSha()
|
|
||||||
// create inventory we're asking for
|
|
||||||
iv1 := wire.NewInvVect(wire.InvTypeBlock, &bHash)
|
|
||||||
gdataMsg := wire.NewMsgGetData()
|
|
||||||
// add inventory
|
|
||||||
err = gdataMsg.AddInvVect(iv1)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
s.outMsgQueue <- gdataMsg
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -49,6 +49,8 @@ func OpenSPV(remoteNode string, hfn, dbfn string,
|
|||||||
}
|
}
|
||||||
// must set this to enable SPV stuff
|
// must set this to enable SPV stuff
|
||||||
myMsgVer.AddService(wire.SFNodeBloom)
|
myMsgVer.AddService(wire.SFNodeBloom)
|
||||||
|
// set this to enable segWit
|
||||||
|
myMsgVer.AddService(wire.SFNodeWitness)
|
||||||
// this actually sends
|
// this actually sends
|
||||||
n, err := wire.WriteMessageN(s.con, myMsgVer, s.localVersion, s.TS.Param.Net)
|
n, err := wire.WriteMessageN(s.con, myMsgVer, s.localVersion, s.TS.Param.Net)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -133,7 +133,8 @@ func CheckDoubleSpends(
|
|||||||
|
|
||||||
// TxToString prints out some info about a transaction. for testing / debugging
|
// TxToString prints out some info about a transaction. for testing / debugging
|
||||||
func TxToString(tx *wire.MsgTx) string {
|
func TxToString(tx *wire.MsgTx) string {
|
||||||
str := fmt.Sprintf("\t - Tx %s\n", tx.TxSha().String())
|
str := fmt.Sprintf("\t size %d wsize %d Tx %s\n",
|
||||||
|
tx.SerializeSize(), tx.SerializeSizeWitness(), tx.TxSha().String())
|
||||||
for i, in := range tx.TxIn {
|
for i, in := range tx.TxIn {
|
||||||
str += fmt.Sprintf("Input %d: %s\n", i, in.PreviousOutPoint.String())
|
str += fmt.Sprintf("Input %d: %s\n", i, in.PreviousOutPoint.String())
|
||||||
str += fmt.Sprintf("SigScript for input %d: %x\n", i, in.SignatureScript)
|
str += fmt.Sprintf("SigScript for input %d: %x\n", i, in.SignatureScript)
|
||||||
@ -146,6 +147,12 @@ func TxToString(tx *wire.MsgTx) string {
|
|||||||
str += fmt.Sprintf("output %d nil (WARNING)\n", i)
|
str += fmt.Sprintf("output %d nil (WARNING)\n", i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for i, wit := range tx.TxWitness {
|
||||||
|
if wit.ScriptWitness != nil {
|
||||||
|
str += fmt.Sprintf("Witness %d: %x\n", i, wit.ScriptWitness)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user