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
11b8d1df
Commit
11b8d1df
authored
Jun 25, 2015
by
Felix Lange
Committed by
Jeffrey Wilcke
Jun 29, 2015
Browse files
Options
Downloads
Patches
Plain Diff
core/types: cache computed transaction values
parent
8743cc1c
Branches
Branches containing commit
Tags
Tags containing commit
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/types/transaction.go
+28
-5
28 additions, 5 deletions
core/types/transaction.go
with
28 additions
and
5 deletions
core/types/transaction.go
+
28
−
5
View file @
11b8d1df
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"math/big"
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
...
...
@@ -20,6 +21,10 @@ func IsContractAddr(addr []byte) bool {
type
Transaction
struct
{
data
txdata
// caches
hash
atomic
.
Value
size
atomic
.
Value
from
atomic
.
Value
}
type
txdata
struct
{
...
...
@@ -88,7 +93,12 @@ func (tx *Transaction) EncodeRLP(w io.Writer) error {
}
func
(
tx
*
Transaction
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
return
s
.
Decode
(
&
tx
.
data
)
_
,
size
,
_
:=
s
.
Kind
()
err
:=
s
.
Decode
(
&
tx
.
data
)
if
err
==
nil
{
tx
.
size
.
Store
(
common
.
StorageSize
(
rlp
.
ListSize
(
size
)))
}
return
err
}
func
(
tx
*
Transaction
)
Data
()
[]
byte
{
return
common
.
CopyBytes
(
tx
.
data
.
Payload
)
}
...
...
@@ -107,6 +117,9 @@ func (tx *Transaction) To() *common.Address {
}
func
(
tx
*
Transaction
)
Hash
()
common
.
Hash
{
if
hash
:=
tx
.
hash
.
Load
();
hash
!=
nil
{
return
hash
.
(
common
.
Hash
)
}
v
:=
rlpHash
([]
interface
{}{
tx
.
data
.
AccountNonce
,
tx
.
data
.
Price
,
...
...
@@ -115,21 +128,31 @@ func (tx *Transaction) Hash() common.Hash {
tx
.
data
.
Amount
,
tx
.
data
.
Payload
,
})
tx
.
hash
.
Store
(
v
)
return
v
}
func
(
tx
*
Transaction
)
Size
()
common
.
StorageSize
{
v
,
_
,
_
:=
rlp
.
EncodeToReader
(
&
tx
.
data
)
return
common
.
StorageSize
(
v
)
if
size
:=
tx
.
size
.
Load
();
size
!=
nil
{
return
size
.
(
common
.
StorageSize
)
}
c
:=
writeCounter
(
0
)
rlp
.
Encode
(
&
c
,
&
tx
.
data
)
tx
.
size
.
Store
(
common
.
StorageSize
(
c
))
return
common
.
StorageSize
(
c
)
}
func
(
tx
*
Transaction
)
From
()
(
common
.
Address
,
error
)
{
pubkey
,
err
:=
tx
.
PublicKey
()
if
from
:=
tx
.
from
.
Load
();
from
!=
nil
{
return
from
.
(
common
.
Address
),
nil
}
pubkey
,
err
:=
tx
.
publicKey
()
if
err
!=
nil
{
return
common
.
Address
{},
err
}
var
addr
common
.
Address
copy
(
addr
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
])[
12
:
])
tx
.
from
.
Store
(
addr
)
return
addr
,
nil
}
...
...
@@ -144,7 +167,7 @@ func (tx *Transaction) SignatureValues() (v byte, r *big.Int, s *big.Int) {
return
tx
.
data
.
V
,
new
(
big
.
Int
)
.
Set
(
tx
.
data
.
R
),
new
(
big
.
Int
)
.
Set
(
tx
.
data
.
S
)
}
func
(
tx
*
Transaction
)
P
ublicKey
()
([]
byte
,
error
)
{
func
(
tx
*
Transaction
)
p
ublicKey
()
([]
byte
,
error
)
{
if
!
crypto
.
ValidateSignatureValues
(
tx
.
data
.
V
,
tx
.
data
.
R
,
tx
.
data
.
S
)
{
return
nil
,
errors
.
New
(
"invalid v, r, s values"
)
}
...
...
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