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
33256837
Commit
33256837
authored
Dec 18, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed refund model
parent
f7287c62
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
17 deletions
+18
-17
state_transition.go
core/state_transition.go
+4
-6
state.go
state/state.go
+10
-7
gh_test.go
tests/vm/gh_test.go
+4
-4
No files found.
core/state_transition.go
View file @
33256837
...
...
@@ -213,12 +213,10 @@ func MakeContract(msg Message, state *state.StateDB) *state.StateObject {
func
(
self
*
StateTransition
)
RefundGas
()
{
coinbaseSub
:=
new
(
big
.
Int
)
.
Set
(
self
.
gas
)
uhalf
:=
new
(
big
.
Int
)
.
Div
(
self
.
GasUsed
(),
ethutil
.
Big2
)
for
addr
,
refs
:=
range
self
.
state
.
Refunds
()
{
for
_
,
ref
:=
range
refs
{
coinbaseSub
.
Add
(
self
.
gas
,
ref
)
refund
:=
ethutil
.
BigMin
(
uhalf
,
ref
)
self
.
state
.
AddBalance
([]
byte
(
addr
),
refund
.
Mul
(
refund
,
self
.
msg
.
GasPrice
()))
}
for
addr
,
ref
:=
range
self
.
state
.
Refunds
()
{
refund
:=
ethutil
.
BigMin
(
uhalf
,
ref
)
coinbaseSub
.
Add
(
self
.
gas
,
refund
)
self
.
state
.
AddBalance
([]
byte
(
addr
),
refund
.
Mul
(
refund
,
self
.
msg
.
GasPrice
()))
}
coinbase
,
sender
:=
self
.
Coinbase
(),
self
.
From
()
...
...
state/state.go
View file @
33256837
...
...
@@ -23,14 +23,14 @@ type StateDB struct {
manifest
*
Manifest
refund
map
[
string
]
[]
*
big
.
Int
refund
map
[
string
]
*
big
.
Int
logs
Logs
}
// Create a new state from a given trie
func
New
(
trie
*
trie
.
Trie
)
*
StateDB
{
return
&
StateDB
{
Trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
(),
refund
:
make
(
map
[
string
]
[]
*
big
.
Int
)}
return
&
StateDB
{
Trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
(),
refund
:
make
(
map
[
string
]
*
big
.
Int
)}
}
func
(
self
*
StateDB
)
EmptyLogs
()
{
...
...
@@ -56,7 +56,10 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
}
func
(
self
*
StateDB
)
Refund
(
addr
[]
byte
,
gas
*
big
.
Int
)
{
self
.
refund
[
string
(
addr
)]
=
append
(
self
.
refund
[
string
(
addr
)],
gas
)
if
self
.
refund
[
string
(
addr
)]
==
nil
{
self
.
refund
[
string
(
addr
)]
=
new
(
big
.
Int
)
}
self
.
refund
[
string
(
addr
)]
.
Add
(
self
.
refund
[
string
(
addr
)],
gas
)
}
func
(
self
*
StateDB
)
AddBalance
(
addr
[]
byte
,
amount
*
big
.
Int
)
{
...
...
@@ -207,7 +210,7 @@ func (self *StateDB) Copy() *StateDB {
}
for
addr
,
refund
:=
range
self
.
refund
{
state
.
refund
[
addr
]
=
refund
state
.
refund
[
addr
]
=
new
(
big
.
Int
)
.
Set
(
refund
)
}
logs
:=
make
(
Logs
,
len
(
self
.
logs
))
...
...
@@ -269,17 +272,17 @@ func (s *StateDB) Sync() {
func
(
self
*
StateDB
)
Empty
()
{
self
.
stateObjects
=
make
(
map
[
string
]
*
StateObject
)
self
.
refund
=
make
(
map
[
string
]
[]
*
big
.
Int
)
self
.
refund
=
make
(
map
[
string
]
*
big
.
Int
)
}
func
(
self
*
StateDB
)
Refunds
()
map
[
string
]
[]
*
big
.
Int
{
func
(
self
*
StateDB
)
Refunds
()
map
[
string
]
*
big
.
Int
{
return
self
.
refund
}
func
(
self
*
StateDB
)
Update
(
gasUsed
*
big
.
Int
)
{
var
deleted
bool
self
.
refund
=
make
(
map
[
string
]
[]
*
big
.
Int
)
self
.
refund
=
make
(
map
[
string
]
*
big
.
Int
)
for
_
,
stateObject
:=
range
self
.
stateObjects
{
if
stateObject
.
remove
{
...
...
tests/vm/gh_test.go
View file @
33256837
...
...
@@ -77,11 +77,11 @@ func RunVmTest(p string, t *testing.T) {
tests
:=
make
(
map
[
string
]
VmTest
)
helper
.
CreateFileTests
(
t
,
p
,
&
tests
)
helper
.
Logger
.
SetLogLevel
(
5
)
//
helper.Logger.SetLogLevel(5)
for
name
,
test
:=
range
tests
{
if
name
!=
"ABAcalls
1"
{
continue
}
// if name != "refund50_
1" {
//
continue
//
}
statedb
:=
state
.
New
(
helper
.
NewTrie
())
for
addr
,
account
:=
range
test
.
Pre
{
obj
:=
StateObjectFromAccount
(
addr
,
account
)
...
...
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