diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-08-17 20:01:41 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-09-22 02:33:28 +0800 |
commit | eaa4473dbd4ad404b85f8f0f63b0418a782351b4 (patch) | |
tree | 27eabb671346c279969caafe28d25a44aef0f9a0 /core/types/transaction.go | |
parent | 12c0afe4fe9f284dd10a80af7744102dac8bf06b (diff) | |
download | go-tangerine-eaa4473dbd4ad404b85f8f0f63b0418a782351b4.tar.gz go-tangerine-eaa4473dbd4ad404b85f8f0f63b0418a782351b4.tar.zst go-tangerine-eaa4473dbd4ad404b85f8f0f63b0418a782351b4.zip |
core, core/types: readd transactions after chain re-org
Added a `Difference` method to `types.Transactions` which sets the
receiver to the difference of a to b (NOTE: not a **and** b).
Transaction pool subscribes to RemovedTransactionEvent adding back to
those potential missing from the chain.
When a chain re-org occurs remove any transactions that were removed
from the canonical chain during the re-org as well as the receipts that
were generated in the process.
Closes #1746
Diffstat (limited to 'core/types/transaction.go')
-rw-r--r-- | core/types/transaction.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go index 8260d7423..7a6c5e088 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -272,14 +272,36 @@ func (tx *Transaction) String() string { // Transaction slice type for basic sorting. type Transactions []*Transaction -func (s Transactions) Len() int { return len(s) } +// Len returns the length of s +func (s Transactions) Len() int { return len(s) } + +// Swap swaps the i'th and the j'th element in s func (s Transactions) Swap(i, j int) { s[i], s[j] = s[j], s[i] } +// GetRlp implements Rlpable and returns the i'th element of s in rlp func (s Transactions) GetRlp(i int) []byte { enc, _ := rlp.EncodeToBytes(s[i]) return enc } +// Returns a new set t which is the difference between a to b +func TxDifference(a, b Transactions) (keep Transactions) { + keep = make(Transactions, 0, len(a)) + + remove := make(map[common.Hash]struct{}) + for _, tx := range b { + remove[tx.Hash()] = struct{}{} + } + + for _, tx := range a { + if _, ok := remove[tx.Hash()]; !ok { + keep = append(keep, tx) + } + } + + return keep +} + type TxByNonce struct{ Transactions } func (s TxByNonce) Less(i, j int) bool { |