_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q35900 | notifyBlock | train | func notifyBlock(chain ChainSource, ro *rescanOptions,
curHeader wire.BlockHeader, curStamp waddrmgr.BlockStamp,
scanning bool) error {
// Find relevant transactions based on watch list. If scanning is
// false, we can safely assume this block has no relevant transactions.
var relevantTxs []*btcutil.Tx
if len(ro... | go | {
"resource": ""
} |
q35901 | extractBlockMatches | train | func extractBlockMatches(chain ChainSource, ro *rescanOptions,
curStamp *waddrmgr.BlockStamp) ([]*btcutil.Tx, error) {
// We've matched. Now we actually get the block and cycle through the
// transactions to see which ones are relevant.
block, err := chain.GetBlock(curStamp.Hash, ro.queryOptions...)
if err != nil... | go | {
"resource": ""
} |
q35902 | notifyBlockWithFilter | train | func notifyBlockWithFilter(chain ChainSource, ro *rescanOptions,
curHeader *wire.BlockHeader, curStamp *waddrmgr.BlockStamp,
filter *gcs.Filter) error {
// Based on what we find within the block or the filter, we'll be
// sending out a set of notifications with transactions that are
// relevant to the rescan.
va... | go | {
"resource": ""
} |
q35903 | matchBlockFilter | train | func matchBlockFilter(ro *rescanOptions, filter *gcs.Filter,
blockHash *chainhash.Hash) (bool, error) {
// Now that we have the filter as well as the block hash of the block
// used to construct the filter, we'll check to see if the block
// matches any items in our watch list.
key := builder.DeriveKey(blockHash)... | go | {
"resource": ""
} |
q35904 | blockFilterMatches | train | func blockFilterMatches(chain ChainSource, ro *rescanOptions,
blockHash *chainhash.Hash) (bool, error) {
// TODO(roasbeef): need to ENSURE always get filter
// Since this method is called when we are not current, and from the
// utxoscanner, we expect more calls to follow for the subsequent
// filters. To speed ... | go | {
"resource": ""
} |
q35905 | updateFilter | train | func (ro *rescanOptions) updateFilter(chain ChainSource, update *updateOptions,
curStamp *waddrmgr.BlockStamp, curHeader *wire.BlockHeader) (bool, error) {
ro.watchAddrs = append(ro.watchAddrs, update.addrs...)
ro.watchInputs = append(ro.watchInputs, update.inputs...)
for _, addr := range update.addrs {
script,... | go | {
"resource": ""
} |
q35906 | spendsWatchedInput | train | func (ro *rescanOptions) spendsWatchedInput(tx *btcutil.Tx) bool {
for _, in := range tx.MsgTx().TxIn {
for _, input := range ro.watchInputs {
switch {
// If we're watching for a zero outpoint, then we should
// match on the output script being spent instead.
case input.OutPoint == zeroOutPoint:
pkSc... | go | {
"resource": ""
} |
q35907 | paysWatchedAddr | train | func (ro *rescanOptions) paysWatchedAddr(tx *btcutil.Tx) (bool, error) {
anyMatchingOutputs := false
txOutLoop:
for outIdx, out := range tx.MsgTx().TxOut {
pkScript := out.PkScript
for _, addr := range ro.watchAddrs {
// We'll convert the address into its matching pkScript
// to in order to check for a ma... | go | {
"resource": ""
} |
q35908 | NewRescan | train | func NewRescan(chain ChainSource, options ...RescanOption) *Rescan {
return &Rescan{
running: make(chan struct{}),
options: options,
updateChan: make(chan *updateOptions),
chain: chain,
}
} | go | {
"resource": ""
} |
q35909 | Start | train | func (r *Rescan) Start() <-chan error {
errChan := make(chan error, 1)
if !atomic.CompareAndSwapUint32(&r.started, 0, 1) {
errChan <- fmt.Errorf("Rescan already started")
return errChan
}
r.wg.Add(1)
go func() {
defer r.wg.Done()
rescanArgs := append(r.options, updateChan(r.updateChan))
err := rescan(... | go | {
"resource": ""
} |
q35910 | AddAddrs | train | func AddAddrs(addrs ...btcutil.Address) UpdateOption {
return func(uo *updateOptions) {
uo.addrs = append(uo.addrs, addrs...)
}
} | go | {
"resource": ""
} |
q35911 | AddInputs | train | func AddInputs(inputs ...InputWithScript) UpdateOption {
return func(uo *updateOptions) {
uo.inputs = append(uo.inputs, inputs...)
}
} | go | {
"resource": ""
} |
q35912 | NewBroadcaster | train | func NewBroadcaster(cfg *Config) *Broadcaster {
b := &Broadcaster{
cfg: *cfg,
broadcastReqs: make(chan *broadcastReq),
transactions: make(map[chainhash.Hash]*wire.MsgTx),
quit: make(chan struct{}),
}
return b
} | go | {
"resource": ""
} |
q35913 | Start | train | func (b *Broadcaster) Start() error {
var err error
b.start.Do(func() {
sub, err := b.cfg.SubscribeBlocks()
if err != nil {
err = fmt.Errorf("unable to subscribe for block "+
"notifications: %v", err)
return
}
b.wg.Add(1)
go b.broadcastHandler(sub)
})
return err
} | go | {
"resource": ""
} |
q35914 | Stop | train | func (b *Broadcaster) Stop() {
b.stop.Do(func() {
close(b.quit)
b.wg.Wait()
})
} | go | {
"resource": ""
} |
q35915 | handleBroadcastReq | train | func (b *Broadcaster) handleBroadcastReq(req *broadcastReq) error {
err := b.cfg.Broadcast(req.tx)
if err != nil && !IsBroadcastError(err, Mempool) {
log.Errorf("Broadcast attempt failed: %v", err)
return err
}
b.transactions[req.tx.TxHash()] = req.tx
return nil
} | go | {
"resource": ""
} |
q35916 | rebroadcast | train | func (b *Broadcaster) rebroadcast() {
if len(b.transactions) == 0 {
return
}
sortedTxs := wtxmgr.DependencySort(b.transactions)
for _, tx := range sortedTxs {
err := b.cfg.Broadcast(tx)
switch {
// If the transaction has already confirmed on-chain, we can
// stop broadcasting it further.
//
// TODO(w... | go | {
"resource": ""
} |
q35917 | Broadcast | train | func (b *Broadcaster) Broadcast(tx *wire.MsgTx) error {
errChan := make(chan error, 1)
select {
case b.broadcastReqs <- &broadcastReq{
tx: tx,
errChan: errChan,
}:
case <-b.quit:
return ErrBroadcasterStopped
}
select {
case err := <-errChan:
return err
case <-b.quit:
return ErrBroadcasterStopp... | go | {
"resource": ""
} |
q35918 | NewSubscriptionManager | train | func NewSubscriptionManager(ntfnSource NotificationSource) *SubscriptionManager {
return &SubscriptionManager{
subscribers: make(map[uint64]*newSubscription),
newSubscriptions: make(chan *newSubscription),
cancelSubscriptions: make(chan *cancelSubscription),
ntfnSource: ntfnSource,
quit: ... | go | {
"resource": ""
} |
q35919 | Start | train | func (m *SubscriptionManager) Start() {
if atomic.AddInt32(&m.started, 1) != 1 {
return
}
log.Debug("Starting block notifications subscription manager")
m.wg.Add(1)
go m.subscriptionHandler()
} | go | {
"resource": ""
} |
q35920 | Stop | train | func (m *SubscriptionManager) Stop() {
if atomic.AddInt32(&m.stopped, 1) != 1 {
return
}
log.Debug("Stopping block notifications subscription manager")
close(m.quit)
m.wg.Wait()
var wg sync.WaitGroup
wg.Add(len(m.subscribers))
for _, subscriber := range m.subscribers {
go func() {
defer wg.Done()
s... | go | {
"resource": ""
} |
q35921 | NewSubscription | train | func (m *SubscriptionManager) NewSubscription(bestHeight uint32) (*Subscription,
error) {
// We'll start by constructing the internal messages that the
// subscription handler will use to register the new client.
sub := &newSubscription{
id: atomic.AddUint64(&m.subscriberCounter, 1),
ntfnChan: make(c... | go | {
"resource": ""
} |
q35922 | handleNewSubscription | train | func (m *SubscriptionManager) handleNewSubscription(sub *newSubscription) error {
log.Infof("Registering block subscription: id=%d", sub.id)
// We'll start by retrieving a backlog of notifications from the
// client's best height.
blocks, currentHeight, err := m.ntfnSource.NotificationsSinceHeight(
sub.bestHeigh... | go | {
"resource": ""
} |
q35923 | cancelSubscription | train | func (m *SubscriptionManager) cancelSubscription(sub *newSubscription) {
select {
case m.cancelSubscriptions <- &cancelSubscription{sub.id}:
case <-m.quit:
}
} | go | {
"resource": ""
} |
q35924 | handleCancelSubscription | train | func (m *SubscriptionManager) handleCancelSubscription(msg *cancelSubscription) {
// First, we'll attempt to look up an existing susbcriber with the given
// ID.
sub, ok := m.subscribers[msg.id]
if !ok {
return
}
log.Infof("Canceling block subscription: id=%d", msg.id)
// If there is one, we'll stop their in... | go | {
"resource": ""
} |
q35925 | notifySubscribers | train | func (m *SubscriptionManager) notifySubscribers(ntfn BlockNtfn) {
log.Tracef("Notifying %v", ntfn)
for _, subscriber := range m.subscribers {
m.notifySubscriber(subscriber, ntfn)
}
} | go | {
"resource": ""
} |
q35926 | notifySubscriber | train | func (m *SubscriptionManager) notifySubscriber(sub *newSubscription,
block BlockNtfn) {
select {
case sub.ntfnQueue.ChanIn() <- block:
case <-sub.quit:
case <-m.quit:
return
}
} | go | {
"resource": ""
} |
q35927 | deliver | train | func (r *GetUtxoRequest) deliver(report *SpendReport, err error) {
select {
case r.resultChan <- &getUtxoResult{report, err}:
default:
log.Warnf("duplicate getutxo result delivered for "+
"outpoint=%v, spend=%v, err=%v",
r.Input.OutPoint, report, err)
}
} | go | {
"resource": ""
} |
q35928 | Result | train | func (r *GetUtxoRequest) Result(cancel <-chan struct{}) (*SpendReport, error) {
r.mu.Lock()
defer r.mu.Unlock()
select {
case result := <-r.resultChan:
// Cache the first result returned, in case we have multiple
// readers calling Result.
if r.result == nil {
r.result = result
}
return r.result.repo... | go | {
"resource": ""
} |
q35929 | NewUtxoScanner | train | func NewUtxoScanner(cfg *UtxoScannerConfig) *UtxoScanner {
scanner := &UtxoScanner{
cfg: cfg,
quit: make(chan struct{}),
shutdown: make(chan struct{}),
}
scanner.cv = sync.NewCond(&scanner.mu)
return scanner
} | go | {
"resource": ""
} |
q35930 | Start | train | func (s *UtxoScanner) Start() error {
if !atomic.CompareAndSwapUint32(&s.started, 0, 1) {
return nil
}
s.wg.Add(1)
go s.batchManager()
return nil
} | go | {
"resource": ""
} |
q35931 | Stop | train | func (s *UtxoScanner) Stop() error {
if !atomic.CompareAndSwapUint32(&s.stopped, 0, 1) {
return nil
}
close(s.quit)
batchShutdown:
for {
select {
case <-s.shutdown:
break batchShutdown
case <-time.After(50 * time.Millisecond):
s.cv.Signal()
}
}
// Cancel all pending get utxo requests that were ... | go | {
"resource": ""
} |
q35932 | Enqueue | train | func (s *UtxoScanner) Enqueue(input *InputWithScript,
birthHeight uint32) (*GetUtxoRequest, error) {
log.Debugf("Enqueuing request for %s with birth height %d",
input.OutPoint.String(), birthHeight)
req := &GetUtxoRequest{
Input: input,
BirthHeight: birthHeight,
resultChan: make(chan *getUtxoResult,... | go | {
"resource": ""
} |
q35933 | dequeueAtHeight | train | func (s *UtxoScanner) dequeueAtHeight(height uint32) []*GetUtxoRequest {
s.cv.L.Lock()
defer s.cv.L.Unlock()
// Take any requests that are too old to go in this batch and keep them for
// the next batch.
for !s.pq.IsEmpty() && s.pq.Peek().BirthHeight < height {
item := heap.Pop(&s.pq).(*GetUtxoRequest)
s.next... | go | {
"resource": ""
} |
q35934 | scanFromHeight | train | func (s *UtxoScanner) scanFromHeight(initHeight uint32) error {
// Before beginning the scan, grab the best block stamp we know of,
// which will serve as an initial estimate for the end height of the
// scan.
bestStamp, err := s.cfg.BestSnapshot()
if err != nil {
return err
}
var (
// startHeight and endHe... | go | {
"resource": ""
} |
q35935 | Push | train | func (pq *GetUtxoRequestPQ) Push(x interface{}) {
item := x.(*GetUtxoRequest)
*pq = append(*pq, item)
} | go | {
"resource": ""
} |
q35936 | Pop | train | func (pq *GetUtxoRequestPQ) Pop() interface{} {
old := *pq
n := len(old)
item := old[n-1]
*pq = old[0 : n-1]
return item
} | go | {
"resource": ""
} |
q35937 | newBlockManager | train | func newBlockManager(s *ChainService,
firstPeerSignal <-chan struct{}) (*blockManager, error) {
targetTimespan := int64(s.chainParams.TargetTimespan / time.Second)
targetTimePerBlock := int64(s.chainParams.TargetTimePerBlock / time.Second)
adjustmentFactor := s.chainParams.RetargetAdjustmentFactor
bm := blockMan... | go | {
"resource": ""
} |
q35938 | Stop | train | func (b *blockManager) Stop() error {
if atomic.AddInt32(&b.shutdown, 1) != 1 {
log.Warnf("Block manager is already in the process of " +
"shutting down")
return nil
}
// We'll send out update signals before the quit to ensure that any
// goroutines waiting on them will properly exit.
done := make(chan str... | go | {
"resource": ""
} |
q35939 | NewPeer | train | func (b *blockManager) NewPeer(sp *ServerPeer) {
// Ignore if we are shutting down.
if atomic.LoadInt32(&b.shutdown) != 0 {
return
}
select {
case b.peerChan <- &newPeerMsg{peer: sp}:
case <-b.quit:
return
}
} | go | {
"resource": ""
} |
q35940 | writeCFHeadersMsg | train | func (b *blockManager) writeCFHeadersMsg(msg *wire.MsgCFHeaders,
store *headerfs.FilterHeaderStore) (*chainhash.Hash, error) {
b.newFilterHeadersMtx.Lock()
defer b.newFilterHeadersMtx.Unlock()
// Check that the PrevFilterHeader is the same as the last stored so we
// can prevent misalignment.
tip, tipHeight, er... | go | {
"resource": ""
} |
q35941 | minCheckpointHeight | train | func minCheckpointHeight(checkpoints map[string][]*chainhash.Hash) uint32 {
// If the map is empty, return 0 immediately.
if len(checkpoints) == 0 {
return 0
}
// Otherwise return the length of the shortest one.
minHeight := uint32(math.MaxUint32)
for _, cps := range checkpoints {
height := uint32(len(cps) *... | go | {
"resource": ""
} |
q35942 | verifyCheckpoint | train | func verifyCheckpoint(prevCheckpoint, nextCheckpoint *chainhash.Hash,
cfheaders *wire.MsgCFHeaders) bool {
if *prevCheckpoint != cfheaders.PrevFilterHeader {
return false
}
lastHeader := cfheaders.PrevFilterHeader
for _, hash := range cfheaders.FilterHashes {
lastHeader = chainhash.DoubleHashH(
append(has... | go | {
"resource": ""
} |
q35943 | checkForCFHeaderMismatch | train | func checkForCFHeaderMismatch(headers map[string]*wire.MsgCFHeaders,
idx int) bool {
// First, see if we have a mismatch.
hash := zeroHash
for _, msg := range headers {
if len(msg.FilterHashes) <= idx {
continue
}
if hash == zeroHash {
hash = *msg.FilterHashes[idx]
continue
}
if hash != *msg.F... | go | {
"resource": ""
} |
q35944 | resolveCFHeaderMismatch | train | func resolveCFHeaderMismatch(block *wire.MsgBlock, fType wire.FilterType,
filtersFromPeers map[string]*gcs.Filter) ([]string, error) {
badPeers := make(map[string]struct{})
blockHash := block.BlockHash()
filterKey := builder.DeriveKey(&blockHash)
log.Infof("Attempting to pinpoint mismatch in cfheaders for block... | go | {
"resource": ""
} |
q35945 | getCFHeadersForAllPeers | train | func (b *blockManager) getCFHeadersForAllPeers(height uint32,
fType wire.FilterType) (map[string]*wire.MsgCFHeaders, int) {
// Create the map we're returning.
headers := make(map[string]*wire.MsgCFHeaders)
// Get the header we expect at either the tip of the block header store
// or at the end of the maximum-siz... | go | {
"resource": ""
} |
q35946 | fetchFilterFromAllPeers | train | func (b *blockManager) fetchFilterFromAllPeers(
height uint32, blockHash chainhash.Hash,
filterType wire.FilterType) map[string]*gcs.Filter {
// We'll use this map to collate all responses we receive from each
// peer.
filterResponses := make(map[string]*gcs.Filter)
// We'll now request the target filter from e... | go | {
"resource": ""
} |
q35947 | getCheckpts | train | func (b *blockManager) getCheckpts(lastHash *chainhash.Hash,
fType wire.FilterType) map[string][]*chainhash.Hash {
checkpoints := make(map[string][]*chainhash.Hash)
getCheckptMsg := wire.NewMsgGetCFCheckpt(fType, lastHash)
b.server.queryAllPeers(
getCheckptMsg,
func(sp *ServerPeer, resp wire.Message, quit chan... | go | {
"resource": ""
} |
q35948 | checkCFCheckptSanity | train | func checkCFCheckptSanity(cp map[string][]*chainhash.Hash,
headerStore *headerfs.FilterHeaderStore) (int, error) {
// Get the known best header to compare against checkpoints.
_, storeTip, err := headerStore.ChainTip()
if err != nil {
return 0, err
}
// Determine the maximum length of each peer's checkpoint l... | go | {
"resource": ""
} |
q35949 | SyncPeer | train | func (b *blockManager) SyncPeer() *ServerPeer {
b.syncPeerMutex.Lock()
defer b.syncPeerMutex.Unlock()
return b.syncPeer
} | go | {
"resource": ""
} |
q35950 | findNextHeaderCheckpoint | train | func (b *blockManager) findNextHeaderCheckpoint(height int32) *chaincfg.Checkpoint {
// There is no next checkpoint if there are none for this current
// network.
checkpoints := b.server.chainParams.Checkpoints
if len(checkpoints) == 0 {
return nil
}
// There is no next checkpoint if the height is already afte... | go | {
"resource": ""
} |
q35951 | findPreviousHeaderCheckpoint | train | func (b *blockManager) findPreviousHeaderCheckpoint(height int32) *chaincfg.Checkpoint {
// Start with the genesis block - earliest checkpoint to which our code
// will want to reset
prevCheckpoint := &chaincfg.Checkpoint{
Height: 0,
Hash: b.server.chainParams.GenesisHash,
}
// Find the latest checkpoint lo... | go | {
"resource": ""
} |
q35952 | IsFullySynced | train | func (b *blockManager) IsFullySynced() bool {
_, blockHeaderHeight, err := b.server.BlockHeaders.ChainTip()
if err != nil {
return false
}
_, filterHeaderHeight, err := b.server.RegFilterHeaders.ChainTip()
if err != nil {
return false
}
// If the block headers and filter headers are not at the same height,... | go | {
"resource": ""
} |
q35953 | BlockHeadersSynced | train | func (b *blockManager) BlockHeadersSynced() bool {
b.syncPeerMutex.RLock()
defer b.syncPeerMutex.RUnlock()
// Figure out the latest block we know.
header, height, err := b.server.BlockHeaders.ChainTip()
if err != nil {
return false
}
// There is no last checkpoint if checkpoints are disabled or there are
//... | go | {
"resource": ""
} |
q35954 | SynchronizeFilterHeaders | train | func (b *blockManager) SynchronizeFilterHeaders(f func(uint32) error) error {
b.newFilterHeadersMtx.RLock()
defer b.newFilterHeadersMtx.RUnlock()
return f(b.filterHeaderTip)
} | go | {
"resource": ""
} |
q35955 | checkHeaderSanity | train | func (b *blockManager) checkHeaderSanity(blockHeader *wire.BlockHeader,
maxTimestamp time.Time, reorgAttempt bool) error {
diff, err := b.calcNextRequiredDifficulty(
blockHeader.Timestamp, reorgAttempt)
if err != nil {
return err
}
stubBlock := btcutil.NewBlock(&wire.MsgBlock{
Header: *blockHeader,
})
err ... | go | {
"resource": ""
} |
q35956 | calcNextRequiredDifficulty | train | func (b *blockManager) calcNextRequiredDifficulty(newBlockTime time.Time,
reorgAttempt bool) (uint32, error) {
hList := b.headerList
if reorgAttempt {
hList = b.reorgList
}
lastNode := hList.Back()
// Genesis block.
if lastNode == nil {
return b.server.chainParams.PowLimitBits, nil
}
// Return the prev... | go | {
"resource": ""
} |
q35957 | onBlockConnected | train | func (b *blockManager) onBlockConnected(header wire.BlockHeader, height uint32) {
select {
case b.blockNtfnChan <- blockntfns.NewBlockConnected(header, height):
case <-b.quit:
}
} | go | {
"resource": ""
} |
q35958 | onBlockDisconnected | train | func (b *blockManager) onBlockDisconnected(headerDisconnected wire.BlockHeader,
heightDisconnected uint32, newChainTip wire.BlockHeader) {
select {
case b.blockNtfnChan <- blockntfns.NewBlockDisconnected(
headerDisconnected, heightDisconnected, newChainTip,
):
case <-b.quit:
}
} | go | {
"resource": ""
} |
q35959 | NotificationsSinceHeight | train | func (b *blockManager) NotificationsSinceHeight(
height uint32) ([]blockntfns.BlockNtfn, uint32, error) {
b.newFilterHeadersMtx.RLock()
defer b.newFilterHeadersMtx.RUnlock()
bestHeight := b.filterHeaderTip
// If a height of 0 is provided by the caller, then a backlog of
// notifications is not needed.
if heig... | go | {
"resource": ""
} |
q35960 | Size | train | func (c *CacheableFilter) Size() (uint64, error) {
f, err := c.Filter.NBytes()
if err != nil {
return 0, err
}
return uint64(len(f)), nil
} | go | {
"resource": ""
} |
q35961 | NewCache | train | func NewCache(capacity uint64) *Cache {
return &Cache{
capacity: capacity,
ll: list.New(),
cache: make(elementMap),
}
} | go | {
"resource": ""
} |
q35962 | evict | train | func (c *Cache) evict(needed uint64) (bool, error) {
if needed > c.capacity {
return false, fmt.Errorf("can't evict %v elements in size, "+
"since capacity is %v", needed, c.capacity)
}
evicted := false
for c.capacity-c.size < needed {
// We still need to evict some more elements.
if c.ll.Len() == 0 {
... | go | {
"resource": ""
} |
q35963 | Get | train | func (c *Cache) Get(key interface{}) (cache.Value, error) {
c.mtx.Lock()
defer c.mtx.Unlock()
el, ok := c.cache[key]
if !ok {
// Element not found in the cache.
return nil, cache.ErrElementNotFound
}
// When the cache needs to evict a element to make space for another
// one, it starts eviction from the ba... | go | {
"resource": ""
} |
q35964 | Len | train | func (c *Cache) Len() int {
c.mtx.RLock()
defer c.mtx.RUnlock()
return c.ll.Len()
} | go | {
"resource": ""
} |
q35965 | NewBoundedMemoryChain | train | func NewBoundedMemoryChain(maxNodes uint32) *BoundedMemoryChain {
return &BoundedMemoryChain{
headPtr: -1,
tailPtr: -1,
maxSize: int32(maxNodes),
chain: make([]Node, maxNodes),
}
} | go | {
"resource": ""
} |
q35966 | IsBroadcastError | train | func IsBroadcastError(err error, codes ...BroadcastErrorCode) bool {
broadcastErr, ok := err.(*BroadcastError)
if !ok {
return false
}
for _, code := range codes {
if broadcastErr.Code == code {
return true
}
}
return false
} | go | {
"resource": ""
} |
q35967 | ParseBroadcastError | train | func ParseBroadcastError(msg *wire.MsgReject, peerAddr string) *BroadcastError {
// We'll determine the appropriate broadcast error code by looking at
// the reject's message code and reason. The only reject codes returned
// from peers (bitcoind and btcd) when attempting to accept a
// transaction into their mempo... | go | {
"resource": ""
} |
q35968 | New | train | func New(db walletdb.DB, params chaincfg.Params) (*FilterStore, error) {
err := walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
// As part of our initial setup, we'll try to create the top
// level filter bucket. If this already exists, then we can
// exit early.
filters, err := tx.CreateTopLevelBuck... | go | {
"resource": ""
} |
q35969 | putFilter | train | func putFilter(bucket walletdb.ReadWriteBucket, hash *chainhash.Hash,
filter *gcs.Filter) error {
if filter == nil {
return bucket.Put(hash[:], nil)
}
bytes, err := filter.NBytes()
if err != nil {
return err
}
return bucket.Put(hash[:], bytes)
} | go | {
"resource": ""
} |
q35970 | newHeaderStore | train | func newHeaderStore(db walletdb.DB, filePath string,
hType HeaderType) (*headerStore, error) {
var flatFileName string
switch hType {
case Block:
flatFileName = "block_headers.bin"
case RegularFilter:
flatFileName = "reg_filter_headers.bin"
default:
return nil, fmt.Errorf("unrecognized filter type: %v", hT... | go | {
"resource": ""
} |
q35971 | NewBlockHeaderStore | train | func NewBlockHeaderStore(filePath string, db walletdb.DB,
netParams *chaincfg.Params) (BlockHeaderStore, error) {
hStore, err := newHeaderStore(db, filePath, Block)
if err != nil {
return nil, err
}
// With the header store created, we'll fetch the file size to see if
// we need to initialize it with the firs... | go | {
"resource": ""
} |
q35972 | toIndexEntry | train | func (b *BlockHeader) toIndexEntry() headerEntry {
return headerEntry{
hash: b.BlockHash(),
height: b.Height,
}
} | go | {
"resource": ""
} |
q35973 | BlockLocatorFromHash | train | func (h *blockHeaderStore) BlockLocatorFromHash(hash *chainhash.Hash) (
blockchain.BlockLocator, error) {
// Lock store for read.
h.mtx.RLock()
defer h.mtx.RUnlock()
return h.blockLocatorFromHash(hash)
} | go | {
"resource": ""
} |
q35974 | CheckConnectivity | train | func (h *blockHeaderStore) CheckConnectivity() error {
// Lock store for read.
h.mtx.RLock()
defer h.mtx.RUnlock()
return walletdb.View(h.db, func(tx walletdb.ReadTx) error {
// First, we'll fetch the root bucket, in order to use that to
// fetch the bucket that houses the header index.
rootBucket := tx.Read... | go | {
"resource": ""
} |
q35975 | NewFilterHeaderStore | train | func NewFilterHeaderStore(filePath string, db walletdb.DB,
filterType HeaderType, netParams *chaincfg.Params) (*FilterHeaderStore, error) {
fStore, err := newHeaderStore(db, filePath, filterType)
if err != nil {
return nil, err
}
// With the header store created, we'll fetch the fiie size to see if
// we need... | go | {
"resource": ""
} |
q35976 | FetchHeader | train | func (f *FilterHeaderStore) FetchHeader(hash *chainhash.Hash) (*chainhash.Hash, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
height, err := f.heightFromHash(hash)
if err != nil {
return nil, err
}
return f.readHeader(height)
} | go | {
"resource": ""
} |
q35977 | FetchHeaderByHeight | train | func (f *FilterHeaderStore) FetchHeaderByHeight(height uint32) (*chainhash.Hash, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
return f.readHeader(height)
} | go | {
"resource": ""
} |
q35978 | FetchHeaderAncestors | train | func (f *FilterHeaderStore) FetchHeaderAncestors(numHeaders uint32,
stopHash *chainhash.Hash) ([]chainhash.Hash, uint32, error) {
// First, we'll find the final header in the range, this will be the
// ending height of our scan.
endHeight, err := f.heightFromHash(stopHash)
if err != nil {
return nil, 0, err
}
... | go | {
"resource": ""
} |
q35979 | toIndexEntry | train | func (f *FilterHeader) toIndexEntry() headerEntry {
return headerEntry{
hash: f.HeaderHash,
height: f.Height,
}
} | go | {
"resource": ""
} |
q35980 | WriteHeaders | train | func (f *FilterHeaderStore) WriteHeaders(hdrs ...FilterHeader) error {
// Lock store for write.
f.mtx.Lock()
defer f.mtx.Unlock()
// If there are 0 headers to be written, return immediately. This
// prevents the newTip assignment from panicking because of an index
// of -1.
if len(hdrs) == 0 {
return nil
}
... | go | {
"resource": ""
} |
q35981 | ChainTip | train | func (f *FilterHeaderStore) ChainTip() (*chainhash.Hash, uint32, error) {
// Lock store for read.
f.mtx.RLock()
defer f.mtx.RUnlock()
_, tipHeight, err := f.chainTip()
if err != nil {
return nil, 0, fmt.Errorf("unable to fetch chain tip: %v", err)
}
latestHeader, err := f.readHeader(tipHeight)
if err != nil... | go | {
"resource": ""
} |
q35982 | RollbackLastBlock | train | func (f *FilterHeaderStore) RollbackLastBlock(newTip *chainhash.Hash) (*waddrmgr.BlockStamp, error) {
// Lock store for write.
f.mtx.Lock()
defer f.mtx.Unlock()
// First, we'll obtain the latest height that the index knows of.
_, chainTipHeight, err := f.chainTip()
if err != nil {
return nil, err
}
// With ... | go | {
"resource": ""
} |
q35983 | search | train | func (results *results) search(result *nmVertex) int {
return sort.Search(len(results.vertices), func(i int) bool {
return !results.vertices[i].less(results.config, result)
})
} | go | {
"resource": ""
} |
q35984 | reSort | train | func (results *results) reSort(vertex *nmVertex) {
results.insert(vertex)
bestGuess := results.vertices[0]
sigma := calculateSigma(len(results.config.Vars), len(results.vertices))
results.pbs.calculateProbabilities(bestGuess, sigma)
results.pbs.sort()
} | go | {
"resource": ""
} |
q35985 | Add | train | func (irt *immutableRangeTree) Add(entries ...Entry) *immutableRangeTree {
if len(entries) == 0 {
return irt
}
cache := newCache(irt.dimensions)
top := make(orderedNodes, len(irt.top))
copy(top, irt.top)
added := uint64(0)
for _, entry := range entries {
irt.add(&top, cache, entry, &added)
}
tree := newI... | go | {
"resource": ""
} |
q35986 | InsertAtDimension | train | func (irt *immutableRangeTree) InsertAtDimension(dimension uint64,
index, number int64) (*immutableRangeTree, Entries, Entries) {
if dimension > irt.dimensions || number == 0 {
return irt, nil, nil
}
modified, deleted := make(Entries, 0, 100), make(Entries, 0, 100)
tree := newImmutableRangeTree(irt.dimensions... | go | {
"resource": ""
} |
q35987 | Set | train | func (e *Error) Set(err error) {
e.lock.Lock()
defer e.lock.Unlock()
e.err = err
} | go | {
"resource": ""
} |
q35988 | Get | train | func (e *Error) Get() error {
e.lock.RLock()
defer e.lock.RUnlock()
return e.err
} | go | {
"resource": ""
} |
q35989 | add | train | func (ot *orderedTree) add(entry Entry) *node {
var node *node
list := &ot.top
for i := uint64(1); i <= ot.dimensions; i++ {
if isLastDimension(ot.dimensions, i) {
overwritten := list.add(
newNode(entry.ValueAtDimension(i), entry, false),
)
if overwritten == nil {
ot.number++
}
return overw... | go | {
"resource": ""
} |
q35990 | Search | train | func (s Int64Slice) Search(x int64) int {
return sort.Search(len(s), func(i int) bool {
return s[i] >= x
})
} | go | {
"resource": ""
} |
q35991 | Exists | train | func (s Int64Slice) Exists(x int64) bool {
i := s.Search(x)
if i == len(s) {
return false
}
return s[i] == x
} | go | {
"resource": ""
} |
q35992 | Insert | train | func (s Int64Slice) Insert(x int64) Int64Slice {
i := s.Search(x)
if i == len(s) {
return append(s, x)
}
if s[i] == x {
return s
}
s = append(s, 0)
copy(s[i+1:], s[i:])
s[i] = x
return s
} | go | {
"resource": ""
} |
q35993 | DefaultConfig | train | func DefaultConfig(persister Persister, comparator Comparator) Config {
return Config{
NodeWidth: 10000,
Persister: persister,
Comparator: comparator,
}
} | go | {
"resource": ""
} |
q35994 | exhaust | train | func (iter *Iterator) exhaust() Entries {
entries := make(Entries, 0, 100)
for it := iter; it.Next(); {
entries = append(entries, it.Value())
}
return entries
} | go | {
"resource": ""
} |
q35995 | roundUp | train | func roundUp(v uint64) uint64 {
v--
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
v |= v >> 32
v++
return v
} | go | {
"resource": ""
} |
q35996 | rebuild | train | func (fi *FastIntegerHashMap) rebuild() {
packets := make(packets, roundUp(uint64(len(fi.packets))+1))
for _, packet := range fi.packets {
if packet == nil {
continue
}
packets.set(packet)
}
fi.packets = packets
} | go | {
"resource": ""
} |
q35997 | Get | train | func (fi *FastIntegerHashMap) Get(key uint64) (uint64, bool) {
return fi.packets.get(key)
} | go | {
"resource": ""
} |
q35998 | Set | train | func (fi *FastIntegerHashMap) Set(key, value uint64) {
if float64(fi.count+1)/float64(len(fi.packets)) > ratio {
fi.rebuild()
}
fi.packets.set(&packet{key: key, value: value})
fi.count++
} | go | {
"resource": ""
} |
q35999 | Exists | train | func (fi *FastIntegerHashMap) Exists(key uint64) bool {
return fi.packets.exists(key)
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.