Block header changed & console miner control
* miner control moved to `admin.miner` * miner option to set extra data * block extra now bytes
This commit is contained in:
parent
3040296beb
commit
9c55576c7b
@ -26,8 +26,6 @@ func (js *jsre) adminBindings() {
|
|||||||
admin := t.Object()
|
admin := t.Object()
|
||||||
admin.Set("suggestPeer", js.suggestPeer)
|
admin.Set("suggestPeer", js.suggestPeer)
|
||||||
admin.Set("startRPC", js.startRPC)
|
admin.Set("startRPC", js.startRPC)
|
||||||
admin.Set("startMining", js.startMining)
|
|
||||||
admin.Set("stopMining", js.stopMining)
|
|
||||||
admin.Set("nodeInfo", js.nodeInfo)
|
admin.Set("nodeInfo", js.nodeInfo)
|
||||||
admin.Set("peers", js.peers)
|
admin.Set("peers", js.peers)
|
||||||
admin.Set("newAccount", js.newAccount)
|
admin.Set("newAccount", js.newAccount)
|
||||||
@ -37,7 +35,30 @@ func (js *jsre) adminBindings() {
|
|||||||
admin.Set("dumpBlock", js.dumpBlock)
|
admin.Set("dumpBlock", js.dumpBlock)
|
||||||
admin.Set("verbosity", js.verbosity)
|
admin.Set("verbosity", js.verbosity)
|
||||||
admin.Set("backtrace", js.backtrace)
|
admin.Set("backtrace", js.backtrace)
|
||||||
admin.Set("hashrate", js.hashrate)
|
|
||||||
|
admin.Set("miner", struct{}{})
|
||||||
|
t, _ = admin.Get("miner")
|
||||||
|
miner := t.Object()
|
||||||
|
miner.Set("start", js.startMining)
|
||||||
|
miner.Set("stop", js.stopMining)
|
||||||
|
miner.Set("hashrate", js.hashrate)
|
||||||
|
miner.Set("setExtra", js.setExtra)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (js *jsre) setExtra(call otto.FunctionCall) otto.Value {
|
||||||
|
extra, err := call.Argument(0).ToString()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return otto.UndefinedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(extra) > 1024 {
|
||||||
|
fmt.Println("error: cannot exceed 1024 bytes")
|
||||||
|
return otto.UndefinedValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
js.ethereum.Miner().SetExtra([]byte(extra))
|
||||||
|
return otto.UndefinedValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (js *jsre) hashrate(otto.FunctionCall) otto.Value {
|
func (js *jsre) hashrate(otto.FunctionCall) otto.Value {
|
||||||
|
@ -55,7 +55,7 @@ func NewCanonical(n int, db common.Database) (*BlockProcessor, error) {
|
|||||||
|
|
||||||
// block time is fixed at 10 seconds
|
// block time is fixed at 10 seconds
|
||||||
func newBlockFromParent(addr common.Address, parent *types.Block) *types.Block {
|
func newBlockFromParent(addr common.Address, parent *types.Block) *types.Block {
|
||||||
block := types.NewBlock(parent.Hash(), addr, parent.Root(), common.BigPow(2, 32), 0, "")
|
block := types.NewBlock(parent.Hash(), addr, parent.Root(), common.BigPow(2, 32), 0, nil)
|
||||||
block.SetUncles(nil)
|
block.SetUncles(nil)
|
||||||
block.SetTransactions(nil)
|
block.SetTransactions(nil)
|
||||||
block.SetReceipts(nil)
|
block.SetReceipts(nil)
|
||||||
|
@ -228,7 +228,7 @@ func (bc *ChainManager) NewBlock(coinbase common.Address) *types.Block {
|
|||||||
root,
|
root,
|
||||||
common.BigPow(2, 32),
|
common.BigPow(2, 32),
|
||||||
0,
|
0,
|
||||||
"")
|
nil)
|
||||||
block.SetUncles(nil)
|
block.SetUncles(nil)
|
||||||
block.SetTransactions(nil)
|
block.SetTransactions(nil)
|
||||||
block.SetReceipts(nil)
|
block.SetReceipts(nil)
|
||||||
|
@ -20,7 +20,7 @@ var ZeroHash160 = make([]byte, 20)
|
|||||||
var ZeroHash512 = make([]byte, 64)
|
var ZeroHash512 = make([]byte, 64)
|
||||||
|
|
||||||
func GenesisBlock(db common.Database) *types.Block {
|
func GenesisBlock(db common.Database) *types.Block {
|
||||||
genesis := types.NewBlock(common.Hash{}, common.Address{}, common.Hash{}, params.GenesisDifficulty, 42, "")
|
genesis := types.NewBlock(common.Hash{}, common.Address{}, common.Hash{}, params.GenesisDifficulty, 42, nil)
|
||||||
genesis.Header().Number = common.Big0
|
genesis.Header().Number = common.Big0
|
||||||
genesis.Header().GasLimit = params.GenesisGasLimit
|
genesis.Header().GasLimit = params.GenesisGasLimit
|
||||||
genesis.Header().GasUsed = common.Big0
|
genesis.Header().GasUsed = common.Big0
|
||||||
|
@ -39,7 +39,7 @@ type Header struct {
|
|||||||
// Creation time
|
// Creation time
|
||||||
Time uint64
|
Time uint64
|
||||||
// Extra data
|
// Extra data
|
||||||
Extra string
|
Extra []byte
|
||||||
// Mix digest for quick checking to prevent DOS
|
// Mix digest for quick checking to prevent DOS
|
||||||
MixDigest common.Hash
|
MixDigest common.Hash
|
||||||
// Nonce
|
// Nonce
|
||||||
@ -121,7 +121,7 @@ type storageblock struct {
|
|||||||
TD *big.Int
|
TD *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlock(parentHash common.Hash, coinbase common.Address, root common.Hash, difficulty *big.Int, nonce uint64, extra string) *Block {
|
func NewBlock(parentHash common.Hash, coinbase common.Address, root common.Hash, difficulty *big.Int, nonce uint64, extra []byte) *Block {
|
||||||
header := &Header{
|
header := &Header{
|
||||||
Root: root,
|
Root: root,
|
||||||
ParentHash: parentHash,
|
ParentHash: parentHash,
|
||||||
@ -371,7 +371,7 @@ func (self *Header) String() string {
|
|||||||
GasLimit: %v
|
GasLimit: %v
|
||||||
GasUsed: %v
|
GasUsed: %v
|
||||||
Time: %v
|
Time: %v
|
||||||
Extra: %v
|
Extra: %s
|
||||||
MixDigest: %x
|
MixDigest: %x
|
||||||
Nonce: %x`,
|
Nonce: %x`,
|
||||||
self.ParentHash, self.UncleHash, self.Coinbase, self.Root, self.TxHash, self.ReceiptHash, self.Bloom, self.Difficulty, self.Number, self.GasLimit, self.GasUsed, self.Time, self.Extra, self.MixDigest, self.Nonce)
|
self.ParentHash, self.UncleHash, self.Coinbase, self.Root, self.TxHash, self.ReceiptHash, self.Bloom, self.Difficulty, self.Number, self.GasLimit, self.GasUsed, self.Time, self.Extra, self.MixDigest, self.Nonce)
|
||||||
|
@ -13,7 +13,6 @@ type Miner struct {
|
|||||||
worker *worker
|
worker *worker
|
||||||
|
|
||||||
MinAcceptedGasPrice *big.Int
|
MinAcceptedGasPrice *big.Int
|
||||||
Extra string
|
|
||||||
|
|
||||||
mining bool
|
mining bool
|
||||||
eth core.Backend
|
eth core.Backend
|
||||||
@ -58,3 +57,7 @@ func (self *Miner) Stop() {
|
|||||||
func (self *Miner) HashRate() int64 {
|
func (self *Miner) HashRate() int64 {
|
||||||
return self.worker.HashRate()
|
return self.worker.HashRate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Miner) SetExtra(extra []byte) {
|
||||||
|
self.worker.extra = extra
|
||||||
|
}
|
||||||
|
@ -69,10 +69,12 @@ type worker struct {
|
|||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
atWork int64
|
atWork int64
|
||||||
|
|
||||||
eth core.Backend
|
eth core.Backend
|
||||||
chain *core.ChainManager
|
chain *core.ChainManager
|
||||||
proc *core.BlockProcessor
|
proc *core.BlockProcessor
|
||||||
|
|
||||||
coinbase common.Address
|
coinbase common.Address
|
||||||
|
extra []byte
|
||||||
|
|
||||||
current *environment
|
current *environment
|
||||||
|
|
||||||
@ -213,6 +215,7 @@ func (self *worker) commitNewWork() {
|
|||||||
if block.Time() == self.chain.CurrentBlock().Time() {
|
if block.Time() == self.chain.CurrentBlock().Time() {
|
||||||
block.Header().Time++
|
block.Header().Time++
|
||||||
}
|
}
|
||||||
|
block.Header().Extra = self.extra
|
||||||
|
|
||||||
self.current = env(block, self.eth)
|
self.current = env(block, self.eth)
|
||||||
for _, ancestor := range self.chain.GetAncestors(block, 7) {
|
for _, ancestor := range self.chain.GetAncestors(block, 7) {
|
||||||
|
@ -186,7 +186,7 @@ func mustConvertHeader(in btHeader) *types.Header {
|
|||||||
Coinbase: mustConvertAddress(in.Coinbase),
|
Coinbase: mustConvertAddress(in.Coinbase),
|
||||||
UncleHash: mustConvertHash(in.UncleHash),
|
UncleHash: mustConvertHash(in.UncleHash),
|
||||||
ParentHash: mustConvertHash(in.ParentHash),
|
ParentHash: mustConvertHash(in.ParentHash),
|
||||||
Extra: string(mustConvertBytes(in.ExtraData)),
|
Extra: mustConvertBytes(in.ExtraData),
|
||||||
GasUsed: mustConvertBigInt10(in.GasUsed),
|
GasUsed: mustConvertBigInt10(in.GasUsed),
|
||||||
GasLimit: mustConvertBigInt10(in.GasLimit),
|
GasLimit: mustConvertBigInt10(in.GasLimit),
|
||||||
Difficulty: mustConvertBigInt10(in.Difficulty),
|
Difficulty: mustConvertBigInt10(in.Difficulty),
|
||||||
|
Loading…
Reference in New Issue
Block a user