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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
e98b53bb
Commit
e98b53bb
authored
Feb 25, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
WIP Observing pattern
parent
4b8c50e2
No related branches found
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ethchain/transaction_pool.go
+33
-8
33 additions, 8 deletions
ethchain/transaction_pool.go
with
33 additions
and
8 deletions
ethchain/transaction_pool.go
+
33
−
8
View file @
e98b53bb
...
@@ -17,6 +17,17 @@ const (
...
@@ -17,6 +17,17 @@ const (
)
)
type
TxPoolHook
chan
*
Transaction
type
TxPoolHook
chan
*
Transaction
type
TxMsgTy
byte
const
(
TxPre
=
iota
TxPost
)
type
TxMsg
struct
{
Tx
*
Transaction
Type
TxMsgTy
}
func
FindTx
(
pool
*
list
.
List
,
finder
func
(
*
Transaction
,
*
list
.
Element
)
bool
)
*
Transaction
{
func
FindTx
(
pool
*
list
.
List
,
finder
func
(
*
Transaction
,
*
list
.
Element
)
bool
)
*
Transaction
{
for
e
:=
pool
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
for
e
:=
pool
.
Front
();
e
!=
nil
;
e
=
e
.
Next
()
{
...
@@ -59,6 +70,8 @@ type TxPool struct {
...
@@ -59,6 +70,8 @@ type TxPool struct {
BlockManager
*
BlockManager
BlockManager
*
BlockManager
SecondaryProcessor
TxProcessor
SecondaryProcessor
TxProcessor
subscribers
[]
chan
TxMsg
}
}
func
NewTxPool
()
*
TxPool
{
func
NewTxPool
()
*
TxPool
{
...
@@ -73,21 +86,17 @@ func NewTxPool() *TxPool {
...
@@ -73,21 +86,17 @@ func NewTxPool() *TxPool {
// Blocking function. Don't use directly. Use QueueTransaction instead
// Blocking function. Don't use directly. Use QueueTransaction instead
func
(
pool
*
TxPool
)
addTransaction
(
tx
*
Transaction
)
{
func
(
pool
*
TxPool
)
addTransaction
(
tx
*
Transaction
)
{
log
.
Println
(
"Adding tx to pool"
)
pool
.
mutex
.
Lock
()
pool
.
mutex
.
Lock
()
pool
.
pool
.
PushBack
(
tx
)
pool
.
pool
.
PushBack
(
tx
)
pool
.
mutex
.
Unlock
()
pool
.
mutex
.
Unlock
()
// Broadcast the transaction to the rest of the peers
// Broadcast the transaction to the rest of the peers
pool
.
Speaker
.
Broadcast
(
ethwire
.
MsgTxTy
,
[]
interface
{}{
tx
.
RlpData
()})
pool
.
Speaker
.
Broadcast
(
ethwire
.
MsgTxTy
,
[]
interface
{}{
tx
.
RlpData
()})
log
.
Println
(
"broadcasting it"
)
}
}
// Process transaction validates the Tx and processes funds from the
// Process transaction validates the Tx and processes funds from the
// sender to the recipient.
// sender to the recipient.
func
(
pool
*
TxPool
)
ProcessTransaction
(
tx
*
Transaction
,
block
*
Block
)
(
err
error
)
{
func
(
pool
*
TxPool
)
ProcessTransaction
(
tx
*
Transaction
,
block
*
Block
)
(
err
error
)
{
log
.
Printf
(
"[TXPL] Processing Tx %x
\n
"
,
tx
.
Hash
())
defer
func
()
{
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
if
r
:=
recover
();
r
!=
nil
{
log
.
Println
(
r
)
log
.
Println
(
r
)
...
@@ -132,6 +141,11 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error
...
@@ -132,6 +141,11 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, block *Block) (err error
block
.
UpdateAddr
(
tx
.
Sender
(),
sender
)
block
.
UpdateAddr
(
tx
.
Sender
(),
sender
)
log
.
Printf
(
"[TXPL] Processed Tx %x
\n
"
,
tx
.
Hash
())
// Notify the subscribers
pool
.
notifySubscribers
(
TxPost
,
tx
)
return
return
}
}
...
@@ -145,7 +159,8 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
...
@@ -145,7 +159,8 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
}
}
// Get the sender
// Get the sender
sender
:=
block
.
GetAddr
(
tx
.
Sender
())
accountState
:=
pool
.
BlockManager
.
GetAddrState
(
tx
.
Sender
())
sender
:=
accountState
.
Account
totAmount
:=
new
(
big
.
Int
)
.
Add
(
tx
.
Value
,
new
(
big
.
Int
)
.
Mul
(
TxFee
,
TxFeeRat
))
totAmount
:=
new
(
big
.
Int
)
.
Add
(
tx
.
Value
,
new
(
big
.
Int
)
.
Mul
(
TxFee
,
TxFeeRat
))
// Make sure there's enough in the sender's account. Having insufficient
// Make sure there's enough in the sender's account. Having insufficient
...
@@ -185,9 +200,8 @@ out:
...
@@ -185,9 +200,8 @@ out:
// doesn't matter since this is a goroutine
// doesn't matter since this is a goroutine
pool
.
addTransaction
(
tx
)
pool
.
addTransaction
(
tx
)
if
pool
.
SecondaryProcessor
!=
nil
{
// Notify the subscribers
pool
.
SecondaryProcessor
.
ProcessTransaction
(
tx
)
pool
.
notifySubscribers
(
TxPre
,
tx
)
}
}
}
case
<-
pool
.
quit
:
case
<-
pool
.
quit
:
break
out
break
out
...
@@ -231,3 +245,14 @@ func (pool *TxPool) Stop() {
...
@@ -231,3 +245,14 @@ func (pool *TxPool) Stop() {
pool
.
Flush
()
pool
.
Flush
()
}
}
func
(
pool
*
TxPool
)
Subscribe
(
channel
chan
TxMsg
)
{
pool
.
subscribers
=
append
(
pool
.
subscribers
,
channel
)
}
func
(
pool
*
TxPool
)
notifySubscribers
(
ty
TxMsgTy
,
tx
*
Transaction
)
{
msg
:=
TxMsg
{
Type
:
ty
,
Tx
:
tx
}
for
_
,
subscriber
:=
range
pool
.
subscribers
{
subscriber
<-
msg
}
}
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