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
df7967c5
Commit
df7967c5
authored
Jan 17, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ECmul tmp
parent
815313c7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
12 deletions
+23
-12
block_manager.go
block_manager.go
+22
-11
block_manager_test.go
block_manager_test.go
+1
-1
No files found.
block_manager.go
View file @
df7967c5
...
@@ -5,7 +5,7 @@ import (
...
@@ -5,7 +5,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"github.com/ethereum/ethutil-go"
"github.com/ethereum/ethutil-go"
"github.com/obscuren/secp256-go"
"github.com/obscuren/secp256
k1
-go"
"log"
"log"
"math"
"math"
"math/big"
"math/big"
...
@@ -46,17 +46,20 @@ type BlockManager struct {
...
@@ -46,17 +46,20 @@ type BlockManager struct {
// The block chain :)
// The block chain :)
bc
*
BlockChain
bc
*
BlockChain
// Stack for processing contracts
stack
*
Stack
// Last known block number
// Last known block number
LastBlockNumber
*
big
.
Int
LastBlockNumber
*
big
.
Int
// Stack for processing contracts
stack
*
Stack
// non-persistent key/value memory storage
mem
map
[
string
]
string
}
}
func
NewBlockManager
()
*
BlockManager
{
func
NewBlockManager
()
*
BlockManager
{
bm
:=
&
BlockManager
{
bm
:=
&
BlockManager
{
bc
:
NewBlockChain
(),
bc
:
NewBlockChain
(),
stack
:
NewStack
(),
stack
:
NewStack
(),
mem
:
make
(
map
[
string
]
string
),
}
}
// Set the last known block number based on the blockchains last
// Set the last known block number based on the blockchains last
...
@@ -100,24 +103,27 @@ func (bm *BlockManager) ProcessBlock(block *ethutil.Block) error {
...
@@ -100,24 +103,27 @@ func (bm *BlockManager) ProcessBlock(block *ethutil.Block) error {
<-
lockChan
<-
lockChan
}
}
// Calculate the new total difficulty and sync back to the db
if
bm
.
CalculateTD
(
block
)
{
if
bm
.
CalculateTD
(
block
)
{
ethutil
.
Config
.
Db
.
Put
(
block
.
Hash
(),
block
.
MarshalRlp
())
ethutil
.
Config
.
Db
.
Put
(
block
.
Hash
(),
block
.
RlpEncode
())
bm
.
bc
.
LastBlock
=
block
bm
.
bc
.
LastBlock
=
block
}
}
return
nil
return
nil
}
}
// Unexported method for writing extra non-essential block info to the db
func
(
bm
*
BlockManager
)
writeBlockInfo
(
block
*
ethutil
.
Block
)
{
func
(
bm
*
BlockManager
)
writeBlockInfo
(
block
*
ethutil
.
Block
)
{
bi
:=
ethutil
.
BlockInfo
{
Number
:
bm
.
LastBlockNumber
.
Add
(
bm
.
LastBlockNumber
,
big
.
NewInt
(
1
))}
bi
:=
ethutil
.
BlockInfo
{
Number
:
bm
.
LastBlockNumber
.
Add
(
bm
.
LastBlockNumber
,
big
.
NewInt
(
1
))}
ethutil
.
Config
.
Db
.
Put
(
append
(
block
.
Hash
(),
[]
byte
(
"Info"
)
...
),
bi
.
MarshalRlp
())
// For now we use the block hash with the words "info" appended as key
ethutil
.
Config
.
Db
.
Put
(
append
(
block
.
Hash
(),
[]
byte
(
"Info"
)
...
),
bi
.
RlpEncode
())
}
}
func
(
bm
*
BlockManager
)
BlockInfo
(
block
*
ethutil
.
Block
)
ethutil
.
BlockInfo
{
func
(
bm
*
BlockManager
)
BlockInfo
(
block
*
ethutil
.
Block
)
ethutil
.
BlockInfo
{
bi
:=
ethutil
.
BlockInfo
{}
bi
:=
ethutil
.
BlockInfo
{}
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
(
append
(
block
.
Hash
(),
[]
byte
(
"Info"
)
...
))
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
(
append
(
block
.
Hash
(),
[]
byte
(
"Info"
)
...
))
bi
.
UnmarshalRlp
(
data
)
bi
.
RlpDecode
(
data
)
return
bi
return
bi
}
}
...
@@ -196,7 +202,7 @@ func (bm *BlockManager) AccumelateRewards(block *ethutil.Block) error {
...
@@ -196,7 +202,7 @@ func (bm *BlockManager) AccumelateRewards(block *ethutil.Block) error {
// Reward amount of ether to the coinbase address
// Reward amount of ether to the coinbase address
ether
.
AddFee
(
ethutil
.
CalculateBlockReward
(
block
,
len
(
block
.
Uncles
)))
ether
.
AddFee
(
ethutil
.
CalculateBlockReward
(
block
,
len
(
block
.
Uncles
)))
block
.
State
()
.
Update
(
block
.
Coinbase
,
string
(
ether
.
MarshalRlp
()))
block
.
State
()
.
Update
(
block
.
Coinbase
,
string
(
ether
.
RlpEncode
()))
// TODO Reward each uncle
// TODO Reward each uncle
...
@@ -444,19 +450,24 @@ out:
...
@@ -444,19 +450,24 @@ out:
case
oECMUL
:
case
oECMUL
:
y
:=
bm
.
stack
.
Pop
()
y
:=
bm
.
stack
.
Pop
()
x
:=
bm
.
stack
.
Pop
()
x
:=
bm
.
stack
.
Pop
()
n
:=
bm
.
stack
.
Pop
()
//
n := bm.stack.Pop()
if
ethutil
.
Big
(
x
)
.
Cmp
(
ethutil
.
Big
(
y
))
//if ethutil.Big(x).Cmp(ethutil.Big(y)) {
data
:=
new
(
bytes
.
Buffer
)
data
:=
new
(
bytes
.
Buffer
)
data
.
WriteString
(
x
)
data
.
WriteString
(
x
)
data
.
WriteString
(
y
)
data
.
WriteString
(
y
)
if
secp256
.
VerifyPubkeyValidity
(
data
.
Bytes
())
==
1
{
if
secp256
k1
.
VerifyPubkeyValidity
(
data
.
Bytes
())
==
1
{
// TODO
// TODO
}
else
{
}
else
{
// Invalid, push infinity
// Invalid, push infinity
bm
.
stack
.
Push
(
"0"
)
bm
.
stack
.
Push
(
"0"
)
bm
.
stack
.
Push
(
"0"
)
bm
.
stack
.
Push
(
"0"
)
}
}
//} else {
// // Invalid, push infinity
// bm.stack.Push("0")
// bm.stack.Push("0")
//}
case
oECADD
:
case
oECADD
:
case
oECSIGN
:
case
oECSIGN
:
...
...
block_manager_test.go
View file @
df7967c5
...
@@ -69,7 +69,7 @@ func TestVm(t *testing.T) {
...
@@ -69,7 +69,7 @@ func TestVm(t *testing.T) {
tx := NewTransaction("1e8a42ea8cce13", 100, []string{})
tx := NewTransaction("1e8a42ea8cce13", 100, []string{})
block := CreateBlock("", 0, "", "c014ba53", 0, 0, "", []*Transaction{ctrct, tx})
block := CreateBlock("", 0, "", "c014ba53", 0, 0, "", []*Transaction{ctrct, tx})
db.Put(block.Hash(), block.
MarshalRlp
())
db.Put(block.Hash(), block.
RlpEncode
())
bm := NewBlockManager()
bm := NewBlockManager()
bm.ProcessBlock( block )
bm.ProcessBlock( block )
...
...
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