Exemplo n.º 1
0
func (a *Anchor) checkTxMalleation(transaction *btcutil.Tx, details *btcjson.BlockDetails) {
	anchorLog.Debug("in checkTxMalleation")
	dirBlockInfos := make([]interfaces.IDirBlockInfo, 0, len(a.dirBlockInfoSlice))
	for _, v := range a.dirBlockInfoSlice {
		// find those already anchored but no call back yet
		if v.GetBTCBlockHeight() == 0 && bytes.Compare(v.GetBTCTxHash().Bytes(), primitives.NewZeroHash().Bytes()) != 0 {
			dirBlockInfos = append(dirBlockInfos, v)
		}
	}
	sort.Sort(util.ByDirBlockInfoTimestamp(dirBlockInfos))
	anchorLog.Debugf("malleated tx candidate count=%d, dirBlockInfo list=%s\n", len(dirBlockInfos), spew.Sdump(dirBlockInfos))
	for _, dirBlockInfo := range dirBlockInfos {
		tx, err := a.wclient.GetRawTransaction(toShaHash(dirBlockInfo.GetBTCTxHash()))
		if err != nil {
			anchorLog.Debugf(err.Error())
			continue
		}
		anchorLog.Debugf("GetRawTransaction=%s, dirBlockInfo=%s\n", spew.Sdump(tx), spew.Sdump(dirBlockInfo))
		// compare OP_RETURN
		if reflect.DeepEqual(transaction.MsgTx().TxOut[0], tx.MsgTx().TxOut[0]) {
			anchorLog.Debugf("Tx Malleated: original.txid=%s, malleated.txid=%s\n", dirBlockInfo.GetBTCTxHash().(*primitives.Hash).BTCString(), transaction.Sha().String())
			a.doSaveDirBlockInfo(transaction, details, dirBlockInfo.(*dbInfo.DirBlockInfo), true)
			break
		}
	}
}
Exemplo n.º 2
0
func (a *Anchor) checkTxConfirmations() {
	timeNow := time.Now().Unix()
	time1 := 60 * 5 * a.confirmationsNeeded
	sort.Sort(util.ByDirBlockInfoTimestamp(a.dirBlockInfoSlice))
	for i, dirBlockInfo := range a.dirBlockInfoSlice {
		lapse := timeNow - dirBlockInfo.GetTimestamp().GetTimeSeconds()
		if lapse > int64(time1) {
			anchorLog.Debugf("checkTxConfirmations: time lapse=%d", lapse)
			a.checkConfirmations(dirBlockInfo.(*dbInfo.DirBlockInfo), i)
		}
	}
}
Exemplo n.º 3
0
func (a *Anchor) checkForAnchor() {
	timeNow := time.Now().Unix()
	time0 := 60 * 60 * a.reAnchorAfter
	// anchor the latest dir block first
	sort.Sort(sort.Reverse(util.ByDirBlockInfoTimestamp(a.dirBlockInfoSlice)))
	for _, dirBlockInfo := range a.dirBlockInfoSlice {
		if bytes.Compare(dirBlockInfo.GetBTCTxHash().Bytes(), primitives.NewZeroHash().Bytes()) == 0 {
			anchorLog.Debug("first time anchor: ", spew.Sdump(dirBlockInfo))
			a.SendRawTransactionToBTC(dirBlockInfo.GetDBMerkleRoot(), dirBlockInfo.GetDBHeight())
		} else {
			// This is the re-anchor case for the missed callback of malleated tx
			lapse := timeNow - dirBlockInfo.GetTimestamp().GetTimeSeconds()
			if lapse > int64(time0) {
				anchorLog.Debugf("re-anchor: time lapse=%d, %s\n", lapse, spew.Sdump(dirBlockInfo))
				a.SendRawTransactionToBTC(dirBlockInfo.GetDBMerkleRoot(), dirBlockInfo.GetDBHeight())
			}
		}
	}
}