OSDN Git Service

add
authorHAOYUatHZ <haoyu@protonmail.com>
Fri, 14 Jun 2019 02:33:40 +0000 (10:33 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Fri, 14 Jun 2019 02:33:40 +0000 (10:33 +0800)
federation/synchron/mainchain_keeper.go
federation/synchron/sidechain_keeper.go

index e6261ee..0fe7fab 100644 (file)
@@ -237,7 +237,6 @@ func (m *mainchainKeeper) getCrossChainReqs(crossTransactionID uint64, tx *types
 
 func (m *mainchainKeeper) processWithdrawalTx(chain *orm.Chain, block *types.Block, txIndex uint64, tx *types.Tx) error {
        blockHash := block.Hash()
-
        stmt := m.db.Model(&orm.CrossTransaction{}).Where("chain_id != ?", chain.ID).
                Where(&orm.CrossTransaction{
                        DestTxHash: sql.NullString{tx.ID.String(), true},
@@ -250,6 +249,7 @@ func (m *mainchainKeeper) processWithdrawalTx(chain *orm.Chain, block *types.Blo
        })
        if stmt.RowsAffected != 1 {
                log.Warn("row affected != 1, stmt:", stmt)
+               return ErrInconsistentDB
        }
        return stmt.Error
 }
index d990b45..5d8bae6 100644 (file)
@@ -145,7 +145,7 @@ func (s *sidechainKeeper) isWithdrawalTx(tx *types.Tx) bool {
 
 func (s *sidechainKeeper) processDepositTx(chain *orm.Chain, block *types.Block, txIndex uint64, tx *types.Tx) error {
        blockHash := block.Hash()
-       return s.db.Model(&orm.CrossTransaction{}).Where("chain_id != ?", chain.ID).
+       stmt := s.db.Model(&orm.CrossTransaction{}).Where("chain_id != ?", chain.ID).
                Where(&orm.CrossTransaction{
                        DestTxHash: sql.NullString{tx.ID.String(), true},
                        Status:     common.CrossTxSubmittedStatus,
@@ -154,7 +154,12 @@ func (s *sidechainKeeper) processDepositTx(chain *orm.Chain, block *types.Block,
                DestBlockHash:   sql.NullString{blockHash.String(), true},
                DestTxIndex:     sql.NullInt64{int64(txIndex), true},
                Status:          common.CrossTxCompletedStatus,
-       }).Error
+       })
+       if stmt.RowsAffected != 1 {
+               log.Warn("row affected != 1, stmt:", stmt)
+               return ErrInconsistentDB
+       }
+       return stmt.Error
 }
 
 func (s *sidechainKeeper) processWithdrawalTx(chain *orm.Chain, block *types.Block, txStatus *bc.TransactionStatus, txIndex uint64, tx *types.Tx) error {