Пример #1
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)
	}
}
Пример #2
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)
}
Пример #3
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.")
}