Skip to content

Commit

Permalink
handle double spend within pool
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlagore committed Jul 26, 2017
1 parent c5b2ab3 commit 815f38e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ func (p *Pool) SetUnsafe(t *blockchain.Transaction) {
}

// Silently adds a transaction to the pool.
// Deletes a transaction if it exists from the same
// input hash.
func (p *Pool) set(t *blockchain.Transaction) {
if txn, ok := p.ValidTransactions[t.Input.Hash]; ok {
p.Delete(txn.Transaction)
}
vt := &PooledTransaction{
Transaction: t,
Time: time.Now(),
Expand Down
11 changes: 11 additions & 0 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ func TestPop(t *testing.T) {
p := New()
assert.Nil(t, p.Pop())
}

func TestSetDedupes(t *testing.T) {
p := New()
t1 := blockchain.NewTestTransaction()
t2 := blockchain.NewTestTransaction()
t1.Input.Hash = t2.Input.Hash
p.SetUnsafe(t1)
p.SetUnsafe(t2)
assert.Equal(t, p.Peek(), t2)
assert.Equal(t, p.Len(), 1)
}

0 comments on commit 815f38e

Please sign in to comment.