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
cda88ce3
Commit
cda88ce3
authored
Mar 13, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Implemented a manage state for keeping track of nonces
parent
aa9f981d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/chain_manager.go
+6
-5
6 additions, 5 deletions
core/chain_manager.go
state/managed_state.go
+56
-0
56 additions, 0 deletions
state/managed_state.go
xeth/xeth.go
+1
-1
1 addition, 1 deletion
xeth/xeth.go
with
63 additions
and
6 deletions
core/chain_manager.go
+
6
−
5
View file @
cda88ce3
...
@@ -86,7 +86,7 @@ type ChainManager struct {
...
@@ -86,7 +86,7 @@ type ChainManager struct {
lastBlockHash
[]
byte
lastBlockHash
[]
byte
transState
*
state
.
StateDB
transState
*
state
.
StateDB
txState
*
state
.
State
DB
txState
*
state
.
Managed
State
quit
chan
struct
{}
quit
chan
struct
{}
}
}
...
@@ -95,7 +95,8 @@ func NewChainManager(blockDb, stateDb ethutil.Database, mux *event.TypeMux) *Cha
...
@@ -95,7 +95,8 @@ func NewChainManager(blockDb, stateDb ethutil.Database, mux *event.TypeMux) *Cha
bc
:=
&
ChainManager
{
blockDb
:
blockDb
,
stateDb
:
stateDb
,
genesisBlock
:
GenesisBlock
(
stateDb
),
eventMux
:
mux
,
quit
:
make
(
chan
struct
{})}
bc
:=
&
ChainManager
{
blockDb
:
blockDb
,
stateDb
:
stateDb
,
genesisBlock
:
GenesisBlock
(
stateDb
),
eventMux
:
mux
,
quit
:
make
(
chan
struct
{})}
bc
.
setLastBlock
()
bc
.
setLastBlock
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
bc
.
txState
=
bc
.
State
()
.
Copy
()
// Take ownership of this particular state
bc
.
txState
=
state
.
ManageState
(
bc
.
State
()
.
Copy
())
go
bc
.
update
()
go
bc
.
update
()
return
bc
return
bc
...
@@ -144,17 +145,17 @@ func (self *ChainManager) TransState() *state.StateDB {
...
@@ -144,17 +145,17 @@ func (self *ChainManager) TransState() *state.StateDB {
return
self
.
transState
return
self
.
transState
}
}
func
(
self
*
ChainManager
)
TxState
()
*
state
.
State
DB
{
func
(
self
*
ChainManager
)
TxState
()
*
state
.
Managed
State
{
self
.
tsmu
.
RLock
()
self
.
tsmu
.
RLock
()
defer
self
.
tsmu
.
RUnlock
()
defer
self
.
tsmu
.
RUnlock
()
return
self
.
txState
return
self
.
txState
}
}
func
(
self
*
ChainManager
)
setTxState
(
state
*
state
.
StateDB
)
{
func
(
self
*
ChainManager
)
setTxState
(
state
db
*
state
.
StateDB
)
{
self
.
tsmu
.
Lock
()
self
.
tsmu
.
Lock
()
defer
self
.
tsmu
.
Unlock
()
defer
self
.
tsmu
.
Unlock
()
self
.
txState
=
state
self
.
txState
=
state
.
ManageState
(
statedb
)
}
}
func
(
self
*
ChainManager
)
setTransState
(
statedb
*
state
.
StateDB
)
{
func
(
self
*
ChainManager
)
setTransState
(
statedb
*
state
.
StateDB
)
{
...
...
This diff is collapsed.
Click to expand it.
state/managed_state.go
0 → 100644
+
56
−
0
View file @
cda88ce3
package
state
import
"sync"
type
ManagedState
struct
{
*
StateDB
mu
sync
.
RWMutex
accounts
map
[
string
]
*
StateObject
}
func
ManageState
(
statedb
*
StateDB
)
*
ManagedState
{
return
&
ManagedState
{
StateDB
:
statedb
,
accounts
:
make
(
map
[
string
]
*
StateObject
),
}
}
func
(
ms
*
ManagedState
)
IncrementNonce
(
addr
[]
byte
)
{
ms
.
mu
.
Lock
()
defer
ms
.
mu
.
Unlock
()
ms
.
getAccount
(
addr
)
.
nonce
++
}
func
(
ms
*
ManagedState
)
DecrementNonce
(
addr
[]
byte
)
{
// Decrementing a nonce does not mean we are interested in the account
// incrementing only happens if you control the account, therefor
// incrementing behaves differently from decrementing
if
ms
.
hasAccount
(
addr
)
{
ms
.
mu
.
Lock
()
defer
ms
.
mu
.
Unlock
()
ms
.
getAccount
(
addr
)
.
nonce
--
}
}
func
(
ms
*
ManagedState
)
GetNonce
(
addr
[]
byte
)
uint64
{
ms
.
mu
.
RLock
()
defer
ms
.
mu
.
RUnlock
()
return
ms
.
getAccount
(
addr
)
.
nonce
}
func
(
ms
*
ManagedState
)
hasAccount
(
addr
[]
byte
)
bool
{
_
,
ok
:=
ms
.
accounts
[
string
(
addr
)]
return
ok
}
func
(
ms
*
ManagedState
)
getAccount
(
addr
[]
byte
)
*
StateObject
{
if
_
,
ok
:=
ms
.
accounts
[
string
(
addr
)];
!
ok
{
ms
.
accounts
[
string
(
addr
)]
=
ms
.
GetOrNewStateObject
(
addr
)
}
return
ms
.
accounts
[
string
(
addr
)]
}
This diff is collapsed.
Click to expand it.
xeth/xeth.go
+
1
−
1
View file @
cda88ce3
...
@@ -362,7 +362,7 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
...
@@ -362,7 +362,7 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
if
err
:=
self
.
eth
.
TxPool
()
.
Add
(
tx
);
err
!=
nil
{
if
err
:=
self
.
eth
.
TxPool
()
.
Add
(
tx
);
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
state
.
Se
tNonce
(
from
,
nonce
+
1
)
state
.
Incremen
tNonce
(
from
)
if
contractCreation
{
if
contractCreation
{
addr
:=
core
.
AddressFromMessage
(
tx
)
addr
:=
core
.
AddressFromMessage
(
tx
)
...
...
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