good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
maticnetwork
bor
Commits
7c339ff4
Commit
7c339ff4
authored
6 years ago
by
Matthew Halpern
Committed by
Péter Szilágyi
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
light: make transaction pool receiver names consistent (#19000)
parent
4097ba6a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
light/txpool.go
+39
-39
39 additions, 39 deletions
light/txpool.go
with
39 additions
and
39 deletions
light/txpool.go
+
39
−
39
View file @
7c339ff4
...
...
@@ -390,81 +390,81 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
// add validates a new transaction and sets its state pending if processable.
// It also updates the locally stored nonce if necessary.
func
(
self
*
TxPool
)
add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
func
(
pool
*
TxPool
)
add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
hash
:=
tx
.
Hash
()
if
self
.
pending
[
hash
]
!=
nil
{
if
pool
.
pending
[
hash
]
!=
nil
{
return
fmt
.
Errorf
(
"Known transaction (%x)"
,
hash
[
:
4
])
}
err
:=
self
.
validateTx
(
ctx
,
tx
)
err
:=
pool
.
validateTx
(
ctx
,
tx
)
if
err
!=
nil
{
return
err
}
if
_
,
ok
:=
self
.
pending
[
hash
];
!
ok
{
self
.
pending
[
hash
]
=
tx
if
_
,
ok
:=
pool
.
pending
[
hash
];
!
ok
{
pool
.
pending
[
hash
]
=
tx
nonce
:=
tx
.
Nonce
()
+
1
addr
,
_
:=
types
.
Sender
(
self
.
signer
,
tx
)
if
nonce
>
self
.
nonce
[
addr
]
{
self
.
nonce
[
addr
]
=
nonce
addr
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
)
if
nonce
>
pool
.
nonce
[
addr
]
{
pool
.
nonce
[
addr
]
=
nonce
}
// Notify the subscribers. This event is posted in a goroutine
// because it's possible that somewhere during the post "Remove transaction"
// gets called which will then wait for the global tx pool lock and deadlock.
go
self
.
txFeed
.
Send
(
core
.
NewTxsEvent
{
Txs
:
types
.
Transactions
{
tx
}})
go
pool
.
txFeed
.
Send
(
core
.
NewTxsEvent
{
Txs
:
types
.
Transactions
{
tx
}})
}
// Print a log message if low enough level is set
log
.
Debug
(
"Pooled new transaction"
,
"hash"
,
hash
,
"from"
,
log
.
Lazy
{
Fn
:
func
()
common
.
Address
{
from
,
_
:=
types
.
Sender
(
self
.
signer
,
tx
);
return
from
}},
"to"
,
tx
.
To
())
log
.
Debug
(
"Pooled new transaction"
,
"hash"
,
hash
,
"from"
,
log
.
Lazy
{
Fn
:
func
()
common
.
Address
{
from
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
);
return
from
}},
"to"
,
tx
.
To
())
return
nil
}
// Add adds a transaction to the pool if valid and passes it to the tx relay
// backend
func
(
self
*
TxPool
)
Add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
func
(
pool
*
TxPool
)
Add
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
error
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
data
,
err
:=
rlp
.
EncodeToBytes
(
tx
)
if
err
!=
nil
{
return
err
}
if
err
:=
self
.
add
(
ctx
,
tx
);
err
!=
nil
{
if
err
:=
pool
.
add
(
ctx
,
tx
);
err
!=
nil
{
return
err
}
//fmt.Println("Send", tx.Hash())
self
.
relay
.
Send
(
types
.
Transactions
{
tx
})
pool
.
relay
.
Send
(
types
.
Transactions
{
tx
})
self
.
chainDb
.
Put
(
tx
.
Hash
()
.
Bytes
(),
data
)
pool
.
chainDb
.
Put
(
tx
.
Hash
()
.
Bytes
(),
data
)
return
nil
}
// AddTransactions adds all valid transactions to the pool and passes them to
// the tx relay backend
func
(
self
*
TxPool
)
AddBatch
(
ctx
context
.
Context
,
txs
[]
*
types
.
Transaction
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
func
(
pool
*
TxPool
)
AddBatch
(
ctx
context
.
Context
,
txs
[]
*
types
.
Transaction
)
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
var
sendTx
types
.
Transactions
for
_
,
tx
:=
range
txs
{
if
err
:=
self
.
add
(
ctx
,
tx
);
err
==
nil
{
if
err
:=
pool
.
add
(
ctx
,
tx
);
err
==
nil
{
sendTx
=
append
(
sendTx
,
tx
)
}
}
if
len
(
sendTx
)
>
0
{
self
.
relay
.
Send
(
sendTx
)
pool
.
relay
.
Send
(
sendTx
)
}
}
// GetTransaction returns a transaction if it is contained in the pool
// and nil otherwise.
func
(
t
p
*
TxPool
)
GetTransaction
(
hash
common
.
Hash
)
*
types
.
Transaction
{
func
(
p
ool
*
TxPool
)
GetTransaction
(
hash
common
.
Hash
)
*
types
.
Transaction
{
// check the txs first
if
tx
,
ok
:=
t
p
.
pending
[
hash
];
ok
{
if
tx
,
ok
:=
p
ool
.
pending
[
hash
];
ok
{
return
tx
}
return
nil
...
...
@@ -472,13 +472,13 @@ func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction {
// GetTransactions returns all currently processable transactions.
// The returned slice may be modified by the caller.
func
(
self
*
TxPool
)
GetTransactions
()
(
txs
types
.
Transactions
,
err
error
)
{
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
func
(
pool
*
TxPool
)
GetTransactions
()
(
txs
types
.
Transactions
,
err
error
)
{
pool
.
mu
.
RLock
()
defer
pool
.
mu
.
RUnlock
()
txs
=
make
(
types
.
Transactions
,
len
(
self
.
pending
))
txs
=
make
(
types
.
Transactions
,
len
(
pool
.
pending
))
i
:=
0
for
_
,
tx
:=
range
self
.
pending
{
for
_
,
tx
:=
range
pool
.
pending
{
txs
[
i
]
=
tx
i
++
}
...
...
@@ -487,14 +487,14 @@ func (self *TxPool) GetTransactions() (txs types.Transactions, err error) {
// Content retrieves the data content of the transaction pool, returning all the
// pending as well as queued transactions, grouped by account and nonce.
func
(
self
*
TxPool
)
Content
()
(
map
[
common
.
Address
]
types
.
Transactions
,
map
[
common
.
Address
]
types
.
Transactions
)
{
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
func
(
pool
*
TxPool
)
Content
()
(
map
[
common
.
Address
]
types
.
Transactions
,
map
[
common
.
Address
]
types
.
Transactions
)
{
pool
.
mu
.
RLock
()
defer
pool
.
mu
.
RUnlock
()
// Retrieve all the pending transactions and sort by account and by nonce
pending
:=
make
(
map
[
common
.
Address
]
types
.
Transactions
)
for
_
,
tx
:=
range
self
.
pending
{
account
,
_
:=
types
.
Sender
(
self
.
signer
,
tx
)
for
_
,
tx
:=
range
pool
.
pending
{
account
,
_
:=
types
.
Sender
(
pool
.
signer
,
tx
)
pending
[
account
]
=
append
(
pending
[
account
],
tx
)
}
// There are no queued transactions in a light pool, just return an empty map
...
...
@@ -503,20 +503,20 @@ func (self *TxPool) Content() (map[common.Address]types.Transactions, map[common
}
// RemoveTransactions removes all given transactions from the pool.
func
(
self
*
TxPool
)
RemoveTransactions
(
txs
types
.
Transactions
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
func
(
pool
*
TxPool
)
RemoveTransactions
(
txs
types
.
Transactions
)
{
pool
.
mu
.
Lock
()
defer
pool
.
mu
.
Unlock
()
var
hashes
[]
common
.
Hash
batch
:=
self
.
chainDb
.
NewBatch
()
batch
:=
pool
.
chainDb
.
NewBatch
()
for
_
,
tx
:=
range
txs
{
hash
:=
tx
.
Hash
()
delete
(
self
.
pending
,
hash
)
delete
(
pool
.
pending
,
hash
)
batch
.
Delete
(
hash
.
Bytes
())
hashes
=
append
(
hashes
,
hash
)
}
batch
.
Write
()
self
.
relay
.
Discard
(
hashes
)
pool
.
relay
.
Discard
(
hashes
)
}
// RemoveTx removes the transaction with the given hash from the pool.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment