Skip to content

Commit

Permalink
Merge branch 'testnet' into mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
studyzy committed Apr 3, 2020
2 parents 8591db6 + b6dd443 commit 4d9c6a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions txpool2/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (pool *TxPool) AddRemote(tx *modules.Transaction) error {
return nil
}
func (pool *TxPool) checkDuplicateAdd(txHash common.Hash) error {
if exist, _ := pool.dag.IsTransactionExist(txHash); exist {
log.Infof("ignore add dag exist tx[%s] to tx pool", txHash.String())
return ErrDuplicate
}
if _, err := pool.normals.GetTx(txHash); err == nil { //found tx
log.Infof("ignore add duplicate tx[%s] to tx pool", txHash.String())
return ErrDuplicate
Expand Down
12 changes: 11 additions & 1 deletion txpool2/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestTxPool_GetSortTxs(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

txA := mockPaymentTx(Hash("Dag"), 0, 0)
Expand Down Expand Up @@ -108,6 +109,7 @@ func BenchmarkTxPool_AddLocal(b *testing.B) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

txA := mockPaymentTx(Hash("Dag"), 0, 0)
Expand Down Expand Up @@ -140,6 +142,7 @@ func TestTxpoolByRealData(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

pool.AddLocal(tx14f4)
Expand Down Expand Up @@ -172,7 +175,7 @@ func TestTxPool_AddSysContractTx(t *testing.T) {
return nil, ErrNotFound
}).AnyTimes()
pool := mockTxPool(mdag)

mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
req := mockContractInvokeRequest(Hash("dag"), 0, 0, syscontract.TestContractAddress.Bytes())
err := pool.AddLocal(req)
assert.Nil(t, err)
Expand All @@ -199,6 +202,7 @@ func TestTxPool_AddUserContractTx(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

req := mockContractInvokeRequest(Hash("dag"), 0, 0, []byte("user contract"))
Expand Down Expand Up @@ -231,6 +235,7 @@ func TestAddContractInstallTx(t *testing.T) {
func(outpoint *modules.OutPoint) (*modules.Utxo, error) {
return &modules.Utxo{Amount: 123}, nil
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)
err := pool.AddLocal(installTx)
t.Log(err)
Expand All @@ -250,6 +255,7 @@ func TestTxPool_GetUnpackedTxsByAddr(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)
pay1 := mockPaymentTx(Hash("dag"), 0, 0)
pool.AddLocal(pay1)
Expand Down Expand Up @@ -286,6 +292,7 @@ func TestTxPool_SubscribeTxPreEvent(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)
txpoolAddTxCh := make(chan modules.TxPreEvent, 50)
txpoolAddTxSub := pool.SubscribeTxPreEvent(txpoolAddTxCh)
Expand Down Expand Up @@ -346,6 +353,7 @@ func TestTxPool_AddUserContractAndTransferTx(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

reqA := mockContractInvokeRequest(Hash("dag"), 0, 0, []byte("user contract"))
Expand Down Expand Up @@ -400,6 +408,7 @@ func TestTxpoolByRealUserContractTx(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

//真实的几条交易,从前到后是依赖关系
Expand Down Expand Up @@ -464,6 +473,7 @@ func TestTxpoolByRealUserContractTx2(t *testing.T) {
}
return nil, ErrNotFound
}).AnyTimes()
mdag.EXPECT().IsTransactionExist(gomock.Any()).Return(false, nil).AnyTimes()
pool := mockTxPool(mdag)

//真实的几条交易,从前到后是依赖关系
Expand Down

0 comments on commit 4d9c6a1

Please sign in to comment.