Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a0266489
Commit
a0266489
authored
Mar 13, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make remote dominant
parent
b663e8b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
7 deletions
+48
-7
managed_state.go
state/managed_state.go
+17
-3
managed_state_test.go
state/managed_state_test.go
+31
-4
No files found.
state/managed_state.go
View file @
a0266489
...
...
@@ -23,13 +23,19 @@ func ManageState(statedb *StateDB) *ManagedState {
}
}
func
(
ms
*
ManagedState
)
SetState
(
statedb
*
StateDB
)
{
ms
.
mu
.
Lock
()
defer
ms
.
mu
.
Unlock
()
ms
.
StateDB
=
statedb
}
func
(
ms
*
ManagedState
)
RemoveNonce
(
addr
[]
byte
,
n
uint64
)
{
if
ms
.
hasAccount
(
addr
)
{
ms
.
mu
.
Lock
()
defer
ms
.
mu
.
Unlock
()
account
:=
ms
.
getAccount
(
addr
)
if
n
-
account
.
nstart
<
uint64
(
len
(
account
.
nonces
))
{
if
n
-
account
.
nstart
<
=
uint64
(
len
(
account
.
nonces
))
{
reslice
:=
make
([]
bool
,
n
-
account
.
nstart
)
copy
(
reslice
,
account
.
nonces
[
:
n
-
account
.
nstart
])
account
.
nonces
=
reslice
...
...
@@ -47,7 +53,7 @@ func (ms *ManagedState) NewNonce(addr []byte) uint64 {
return
account
.
nstart
+
uint64
(
i
)
}
}
account
.
nonces
=
append
(
account
.
nonces
,
fals
e
)
account
.
nonces
=
append
(
account
.
nonces
,
tru
e
)
return
uint64
(
len
(
account
.
nonces
))
+
account
.
nstart
}
...
...
@@ -57,9 +63,17 @@ func (ms *ManagedState) hasAccount(addr []byte) bool {
}
func
(
ms
*
ManagedState
)
getAccount
(
addr
[]
byte
)
*
account
{
if
_
,
ok
:=
ms
.
accounts
[
string
(
addr
)];
!
ok
{
if
account
,
ok
:=
ms
.
accounts
[
string
(
addr
)];
!
ok
{
so
:=
ms
.
GetOrNewStateObject
(
addr
)
ms
.
accounts
[
string
(
addr
)]
=
newAccount
(
so
)
}
else
{
// Always make sure the state account nonce isn't actually higher
// than the tracked one.
so
:=
ms
.
StateDB
.
GetStateObject
(
addr
)
if
so
!=
nil
&&
uint64
(
len
(
account
.
nonces
))
+
account
.
nstart
<
so
.
nonce
{
ms
.
accounts
[
string
(
addr
)]
=
newAccount
(
so
)
}
}
return
ms
.
accounts
[
string
(
addr
)]
...
...
state/managed_state_test.go
View file @
a0266489
package
state
import
"testing"
import
(
"testing"
var
addr
=
[]
byte
(
"test"
)
"github.com/ethereum/go-ethereum/ethutil"
)
var
addr
=
ethutil
.
Address
([]
byte
(
"test"
))
func
create
()
(
*
ManagedState
,
*
account
)
{
ms
:=
ManageState
(
nil
)
ms
.
accounts
[
string
(
addr
)]
=
newAccount
(
&
StateObject
{
nonce
:
100
})
ms
:=
ManageState
(
&
StateDB
{
stateObjects
:
make
(
map
[
string
]
*
StateObject
)})
so
:=
&
StateObject
{
address
:
addr
,
nonce
:
100
}
ms
.
StateDB
.
stateObjects
[
string
(
addr
)]
=
so
ms
.
accounts
[
string
(
addr
)]
=
newAccount
(
so
)
return
ms
,
ms
.
accounts
[
string
(
addr
)]
}
...
...
@@ -16,6 +22,11 @@ func TestNewNonce(t *testing.T) {
nonce
:=
ms
.
NewNonce
(
addr
)
if
nonce
!=
100
{
t
.
Error
(
"expected nonce 100. got"
,
nonce
)
}
nonce
=
ms
.
NewNonce
(
addr
)
if
nonce
!=
101
{
t
.
Error
(
"expected nonce 101. got"
,
nonce
)
}
}
...
...
@@ -52,3 +63,19 @@ func TestReuse(t *testing.T) {
t
.
Error
(
"expected nonce to be 105. got"
,
nonce
)
}
}
func
TestRemoteNonceChange
(
t
*
testing
.
T
)
{
ms
,
account
:=
create
()
nn
:=
make
([]
bool
,
10
)
for
i
,
_
:=
range
nn
{
nn
[
i
]
=
true
}
account
.
nonces
=
append
(
account
.
nonces
,
nn
...
)
nonce
:=
ms
.
NewNonce
(
addr
)
ms
.
StateDB
.
stateObjects
[
string
(
addr
)]
.
nonce
=
200
nonce
=
ms
.
NewNonce
(
addr
)
if
nonce
!=
200
{
t
.
Error
(
"expected nonce after remote update to be"
,
201
,
"got"
,
nonce
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment