Пример #1
0
func blocksCatchUp() {
	total := cold.Get().Headers().Len()
	db := cold.Get().OutputDB()
	for {
		tag, err := db.Tag()
		if err != nil {
			log.Panicf("Error reading OutputDB tag: %s", err)
		}
		begin := int(tag) + 1
		if begin >= total {
			break
		}
		end, paral, load := swdlParam(begin, total)
		dl := newSwdl(begin, end, paral, load)
		dl.start()
	}
	log.Infoln("Block downloading done.")
}
Пример #2
0
func saveBlock(m btcmsg.Message, i int, verify bool) {
	db := cold.Get().OutputDB()
	bm, _ := m.(*btcmsg.Message_block)
	for _, tx := range bm.Txs {
		ctx := (*catma.Tx)(tx)
		err := catma.VerifyTx(ctx, db, true, false, !verify)
		if err != nil {
			log.Panicf("Process tx %s error: %s", ctx.Hash(), err)
		}
	}
	if err := db.Commit(uint32(i), false); err != nil {
		log.Panicf("db commit error: %s", err)
	}
}
Пример #3
0
func (sw *swdl) start() {
	sw.wg.Add(1) // For doSaveBlocks
	for i := 0; i < sw.paral; i++ {
		go sw.doDownload()
	}
	go sw.doSaveBlock()
	go sw.doSchedule()

	sw.chin <- nil // Trigger downloading
	sw.wg.Wait()

	db := cold.Get().OutputDB()
	if err := db.Commit(uint32(sw.end-1), true); err != nil {
		log.Panicf("db commit error: %s", err)
	}
	log.Infof("Finished downloading from %d to %d", sw.begin, sw.end)
}
Пример #4
0
func moreHeaders() {
	headers := cold.Get().Headers()
	l := headers.GetLocator()
	msg := btcmsg.NewGetHeadersMsg()
	mg := msg.(*btcmsg.Message_getheaders)
	mg.BlockLocators = l
	mg.HashStop = new(klib.Hash256)

	f := func(m btcmsg.Message) (bool, bool) {
		_, ok := m.(*btcmsg.Message_headers)
		return ok, true
	}

	mh := knet.ParalMsgForMsg(mg, f, 3)
	if mh != nil {
		h, _ := mh.(*btcmsg.Message_headers)
		err := headers.Append(h.Headers)
		if err != nil {
			log.Infof("Error appending headers: %s", err)
		}
	}
}
Пример #5
0
func GetInvElem(h int) *InvElement {
	headers := cold.Get().Headers()
	header := headers.Get(h)
	return &InvElement{InvTypeBlock, *(header.Hash())}
}
Пример #6
0
// Destroy blockchain subsystem
func Destroy() error {
	return cold.Get().Destroy()
}
Пример #7
0
// Initialize blockchain subsystem
func Init() error {
	return cold.Get().Init()
}
Пример #8
0
// Returns if we should stop catching up
func headerUpToDate() bool {
	headers := cold.Get().Headers()
	h := headers.Get(headers.Len() - 1)
	return h.Time().Add(time.Hour * 2).After(time.Now())
}