Documentation ¶
Index ¶
- Constants
- Variables
- func BlockOK(blk wire.MsgBlock) bool
- func CheckHeader(r io.ReadSeeker, height, startheight int32, p *coinparam.Params) bool
- func CheckHeaderChain(r io.ReadSeeker, inHeaders []*wire.BlockHeader, p *coinparam.Params) (int32, error)
- func CheckRange(r io.ReadSeeker, first, last, startHeight int32, p *coinparam.Params) bool
- func FindHeader(r io.ReadSeeker, hdr wire.BlockHeader) (int32, error)
- func MakeMerkleParent(left, right *chainhash.Hash) *chainhash.Hash
- type ChainHook
- type HashAndHeight
- type SPVCon
- func (s *SPVCon) AskForBlocks() error
- func (s *SPVCon) AskForHeaders() error
- func (s *SPVCon) AskForTx(txid chainhash.Hash)
- func (s *SPVCon) Connect(remoteNode string) error
- func (s *SPVCon) GetDataHandler(m *wire.MsgGetData)
- func (s *SPVCon) GetHeaderAtHeight(h int32) (*wire.BlockHeader, error)
- func (s *SPVCon) GetHeaderTipHeight() int32
- func (s *SPVCon) GimmeFilter() (*bloom.Filter, error)
- func (s *SPVCon) HeaderHandler(m *wire.MsgHeaders)
- func (s *SPVCon) IngestBlock(m *wire.MsgBlock)
- func (s *SPVCon) IngestHeaders(m *wire.MsgHeaders) (bool, error)
- func (s *SPVCon) IngestMerkleBlock(m *wire.MsgMerkleBlock)
- func (s *SPVCon) InvHandler(m *wire.MsgInv)
- func (s *SPVCon) MatchTx(tx *wire.MsgTx) bool
- func (s *SPVCon) OKTxid(txid *chainhash.Hash, height int32) error
- func (s *SPVCon) PongBack(nonce uint64)
- func (s *SPVCon) PushTx(tx *wire.MsgTx) error
- func (s *SPVCon) RawBlocks() chan *wire.MsgBlock
- func (s *SPVCon) Refilter(f *bloom.Filter)
- func (s *SPVCon) RegisterAddress(adr160 [20]byte) error
- func (s *SPVCon) RegisterOutPoint(op wire.OutPoint) error
- func (s *SPVCon) SendFilter(f *bloom.Filter)
- func (s *SPVCon) Start(startHeight int32, host, path string, params *coinparam.Params) (chan lnutil.TxAndHeight, chan int32, error)
- func (s *SPVCon) TxHandler(tx *wire.MsgTx)
Constants ¶
const ( // version hardcoded for now, probably ok...? // 70012 is for segnet... make this a init var? VERSION = 70012 )
Variables ¶
var (
WitMagicBytes = []byte{0x6a, 0x24, 0xaa, 0x21, 0xa9, 0xed}
)
Functions ¶
func BlockOK ¶
BlockOK checks for block self-consistency. If the block has no wintess txs, and no coinbase witness commitment, it only checks the tx merkle root. If either a witness commitment or any witnesses are detected, it also checks that as well. Returns false if anything goes wrong, true if everything is fine.
func CheckHeader ¶
func CheckHeaderChain ¶
func CheckHeaderChain( r io.ReadSeeker, inHeaders []*wire.BlockHeader, p *coinparam.Params) (int32, error)
CheckHeaderChain takes in the headers message and sees if they all validate. This function also needs read access to the previous headers. Does not deal with re-orgs; assumes new headers link to tip returns true if *all* headers are cool, false if there is any problem Note we don't know what the height is, just the relative height. returnin nil means it worked returns an int32 usually 0, but if there's a reorg, shows what height to reorg back to before adding on the headers
func CheckRange ¶
checkrange verifies a range of headers. it checks their proof of work,
difficulty adjustments, and that they all link in to each other properly. This is the only blockchain technology in the whole code base. Returns false if anything bad happens. Returns true if the range checks out with no errors.
func FindHeader ¶
func FindHeader(r io.ReadSeeker, hdr wire.BlockHeader) (int32, error)
FindHeader will try to find where the header you give it is. it runs backwards to find it and gives up after 1000 headers
Types ¶
type ChainHook ¶
type ChainHook interface { // Note that for reorgs, the height chan just sends a lower height than you // already have, and that means "reorg back!" Start(height int32, host, path string, params *coinparam.Params) ( chan lnutil.TxAndHeight, chan int32, error) // RegisterAddress tells the ChainHook about an address of interest. // Give it an array; Currently needs to be 20 bytes. Only p2pkh / p2wpkh // are supported. // Later could add a separate function for script hashes (20/32) RegisterAddress(address [20]byte) error // RegisterOutPoint tells the ChainHook about an outpoint of interest. RegisterOutPoint(wire.OutPoint) error // PushTx sends a tx out to the network via the ChainHook. // Note that this does NOT register anything in the tx, so by just using this, // nothing will come back about confirmation. It WILL come back with errors // though, so this takes some time. PushTx(tx *wire.MsgTx) error // Request all incoming blocks over this channel. If RawBlocks isn't called, // then the undelying hook package doesn't need to get full blocks. // Currently you always call it with uspv... RawBlocks() chan *wire.MsgBlock }
type HashAndHeight ¶
type HashAndHeight struct {
// contains filtered or unexported fields
}
HashAndHeight is needed instead of just height in case a fullnode responds abnormally (?) by sending out of order merkleblocks. we cache a merkleroot:height pair in the queue so we don't have to look them up from the disk. Also used when inv messages indicate blocks so we can add the header and parse the txs in one request instead of requesting headers first.
func NewRootAndHeight ¶
func NewRootAndHeight(b chainhash.Hash, h int32) (hah HashAndHeight)
NewRootAndHeight saves like 2 lines.
type SPVCon ¶
type SPVCon struct { // Enhanced SPV modes for users who have outgrown easy mode SPV // but have not yet graduated to full nodes. HardMode bool // hard mode doesn't use filters. Ironman bool // ironman only gets blocks, never requests txs. OKTxids map[chainhash.Hash]int32 // known good txids and their heights OKMutex sync.Mutex // TrackingAdrs and OPs are slices of addresses and outpoints to watch for. // Using struct{} saves a byte of RAM but is ugly so I'll use bool. TrackingAdrs map[[20]byte]bool TrackingAdrsMtx sync.Mutex TrackingOPs map[wire.OutPoint]bool TrackingOPsMtx sync.Mutex // TxMap is an in-memory map of all the Txs the SPVCon knows about TxMap map[chainhash.Hash]*wire.MsgTx WBytes uint64 // total bytes written RBytes uint64 // total bytes read Param *coinparam.Params // network parameters (testnet3, segnet, etc) // TxUpToWallit is the channel for sending txs up a level to the wallit. TxUpToWallit chan lnutil.TxAndHeight // CurrentHeightChan is how we tell the wallit when blocks come in CurrentHeightChan chan int32 // RawBlockSender is a channel to send full blocks up to the qln / watchtower // only kicks in when requested from upper layer RawBlockSender chan *wire.MsgBlock // If the above RawBlockSender chan isn't being pulled from, don't send to it RawBlockActive bool // contains filtered or unexported fields }
func (*SPVCon) AskForBlocks ¶
AskForMerkBlocks requests blocks from current to last right now this asks for 1 block per getData message. Maybe it's faster to ask for many in a each message?
func (*SPVCon) AskForHeaders ¶
func (*SPVCon) AskForTx ¶
AskForTx requests a tx we heard about from an inv message. It's one at a time but should be fast enough. I don't like this function because SPV shouldn't even ask...
func (*SPVCon) GetDataHandler ¶
func (s *SPVCon) GetDataHandler(m *wire.MsgGetData)
GetDataHandler responds to requests for tx data, which happen after advertising our txs via an inv message
func (*SPVCon) GetHeaderAtHeight ¶
func (s *SPVCon) GetHeaderAtHeight(h int32) (*wire.BlockHeader, error)
GetHeaderAtHeight gives back a header at the specified height
func (*SPVCon) GetHeaderTipHeight ¶
GetHeaderAtHeight gives back a header at the specified height
func (*SPVCon) GimmeFilter ¶
GimmeFilter ... or I'm gonna fade away
func (*SPVCon) HeaderHandler ¶
func (s *SPVCon) HeaderHandler(m *wire.MsgHeaders)
func (*SPVCon) IngestBlock ¶
IngestBlock is like IngestMerkleBlock but aralphic different enough that it's better to have 2 separate functions
func (*SPVCon) IngestHeaders ¶
func (s *SPVCon) IngestHeaders(m *wire.MsgHeaders) (bool, error)
IngestHeaders takes in a bunch of headers, checks them, and if they're OK, appends them to the loccal header file. If there are no headers, it assumes we're done and returns false. Otherwise it assumes there's more to request and returns true.
func (*SPVCon) IngestMerkleBlock ¶
func (s *SPVCon) IngestMerkleBlock(m *wire.MsgMerkleBlock)
func (*SPVCon) InvHandler ¶
func (*SPVCon) OKTxid ¶
OKTxid assigns a height to a txid. This means that the txid exists at that height, with whatever assurance (for height 0 it's no assurance at all)
func (*SPVCon) Refilter ¶
RefilterLocal reconstructs the local in-memory bloom filter. It does this by calling GimmeFilter() but doesn't broadcast the result.