• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: コミット

Golang implemented sidechain for Bytom


コミットメタ情報

リビジョン9642338b3b27c3a8f748e7a746bef04821d72fe6 (tree)
日時2019-09-11 14:53:28
作者Poseidon <shenao.78@163....>
コミッターPaladz

ログメッセージ

fix mainchain keeper (#398)

* fix mainchain keeper

* opt code

* opt code

* remove config

変更サマリ

差分

--- a/toolbar/federation/synchron/mainchain_keeper.go
+++ b/toolbar/federation/synchron/mainchain_keeper.go
@@ -125,10 +125,8 @@ func (m *mainchainKeeper) isWithdrawalTx(tx *types.Tx) bool {
125125 }
126126 }
127127
128- if sourceTxHash := locateSideChainTx(tx.Outputs[len(tx.Outputs)-1]); sourceTxHash == "" {
129- return false
130- }
131- return true
128+ sourceTxHash := locateSideChainTx(tx.Outputs[len(tx.Outputs)-1])
129+ return sourceTxHash != ""
132130 }
133131
134132 func locateSideChainTx(output *types.TxOutput) string {
@@ -145,7 +143,11 @@ func locateSideChainTx(output *types.TxOutput) string {
145143 return ""
146144 }
147145
148- return string(insts[1].Data)
146+ sourceTxHash := string(insts[1].Data)
147+ if _, err = hex.DecodeString(sourceTxHash); err == nil && len(sourceTxHash) == 64 {
148+ return sourceTxHash
149+ }
150+ return ""
149151 }
150152
151153 func (m *mainchainKeeper) processBlock(db *gorm.DB, block *types.Block, txStatus *bc.TransactionStatus) error {
@@ -257,10 +259,11 @@ func (m *mainchainKeeper) processWithdrawalTx(db *gorm.DB, block *types.Block, t
257259 blockHash := block.Hash()
258260 tx := block.Transactions[txIndex]
259261
260- stmt := db.Model(&orm.CrossTransaction{}).Where(&orm.CrossTransaction{
262+ crossTx := &orm.CrossTransaction{
261263 SourceTxHash: locateSideChainTx(tx.Outputs[len(tx.Outputs)-1]),
262264 Status: common.CrossTxPendingStatus,
263- }).UpdateColumn(&orm.CrossTransaction{
265+ }
266+ stmt := db.Model(&orm.CrossTransaction{}).Where(crossTx).UpdateColumn(&orm.CrossTransaction{
264267 DestBlockHeight: sql.NullInt64{int64(block.Height), true},
265268 DestBlockTimestamp: sql.NullInt64{int64(block.Timestamp), true},
266269 DestBlockHash: sql.NullString{blockHash.String(), true},
@@ -273,7 +276,7 @@ func (m *mainchainKeeper) processWithdrawalTx(db *gorm.DB, block *types.Block, t
273276 }
274277
275278 if stmt.RowsAffected != 1 {
276- return ErrInconsistentDB
279+ log.WithFields(log.Fields{"sourceTxHash": crossTx.SourceTxHash, "destTxHash": tx.ID.String()}).Error("fail to update withdrawal transaction")
277280 }
278281 return nil
279282 }
旧リポジトリブラウザで表示