github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/uspv/spvcon.go (about) 1 package uspv 2 3 import ( 4 "net" 5 "os" 6 "sync" 7 8 "github.com/mit-dci/lit/btcutil/chaincfg/chainhash" 9 "github.com/mit-dci/lit/coinparam" 10 "github.com/mit-dci/lit/lnutil" 11 "github.com/mit-dci/lit/wire" 12 ) 13 14 // SPVCon is a SPV connection to a coin daemon. 15 type SPVCon struct { 16 con net.Conn // the (probably tcp) connection to the node 17 18 // Enhanced SPV modes for users who have outgrown easy mode SPV 19 // but have not yet graduated to full nodes. 20 HardMode bool // hard mode doesn't use filters. 21 Ironman bool // ironman only gets blocks, never requests txs. 22 ProxyURL string // Optionally the URL of a SOCKS5 proxy to use 23 24 headerMutex sync.Mutex 25 headerFile *os.File // file for SPV headers 26 headerStartHeight int32 // first header on disk is nth header in chain 27 28 syncHeight int32 // internal, in memory synchronization height 29 30 OKTxids map[chainhash.Hash]int32 // known good txids and their heights 31 OKMutex sync.Mutex 32 33 // TrackingAdrs and OPs are slices of addresses and outpoints to watch for. 34 // Using struct{} saves a byte of RAM but is ugly so I'll use bool. 35 TrackingAdrs map[[20]byte]bool 36 TrackingAdrsMtx sync.Mutex 37 38 TrackingOPs map[wire.OutPoint]bool 39 TrackingOPsMtx sync.Mutex 40 41 // TxMap is an in-memory map of all the Txs the SPVCon knows about 42 TxMap map[chainhash.Hash]*wire.MsgTx 43 44 //[doesn't work without fancy mutexes, nevermind, just use header file] 45 // localHeight int32 // block height we're on 46 remoteHeight int32 // block height they're on 47 localVersion uint32 // version we report 48 remoteVersion uint32 // version remote node 49 50 // what's the point of the input queue? remove? leave for now... 51 inMsgQueue chan wire.Message // Messages coming in from remote node 52 outMsgQueue chan wire.Message // Messages going out to remote node 53 54 WBytes uint64 // total bytes written 55 RBytes uint64 // total bytes read 56 57 Param *coinparam.Params // network parameters (testnet3, segnet, etc) 58 59 // TxUpToWallit is the channel for sending txs up a level to the wallit. 60 TxUpToWallit chan lnutil.TxAndHeight 61 // CurrentHeightChan is how we tell the wallit when blocks come in 62 CurrentHeightChan chan int32 63 64 // RawBlockSender is a channel to send full blocks up to the qln / watchtower 65 // only kicks in when requested from upper layer 66 RawBlockSender chan *wire.MsgBlock 67 68 // If the above RawBlockSender chan isn't being pulled from, don't send to it 69 RawBlockActive bool 70 71 // RawBlockDistribute is a list of channels that the raw blocks get sent to. 72 // This is so we can have multiple things using and requesting blocks from the 73 // same chainhook. 74 RawBlockDistribute []chan *wire.MsgBlock 75 76 // HeightDistribute is a list, like RawBlockDistribute, of channels where we 77 // send height events 78 HeightDistribute []chan int32 79 80 // for internal use ------------------------- 81 82 // mBlockQueue is for keeping track of what height we've requested. 83 blockQueue chan HashAndHeight 84 // fPositives is a channel to keep track of bloom filter false positives. 85 fPositives chan int32 86 87 // waitState is a channel that is empty while in the header and block 88 // sync modes, but when in the idle state has a "true" in it. 89 inWaitState chan bool 90 randomNodesOK bool 91 }