mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
Merge branch 'develop' into bzz
This commit is contained in:
commit
7aa3ff6ae5
16 changed files with 3978 additions and 103 deletions
|
|
@ -29,6 +29,8 @@ const (
|
||||||
testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674"
|
testKey = "e6fab74a43941f82d89cb7faa408e227cdad3153c4720e540e855c19b15e6674"
|
||||||
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||||
testBalance = "10000000000000000000"
|
testBalance = "10000000000000000000"
|
||||||
|
// of empty string
|
||||||
|
testHash = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -215,6 +217,32 @@ func TestCheckTestAccountBalance(t *testing.T) {
|
||||||
checkEvalJSON(t, repl, `eth.getBalance(primary)`, `"`+testBalance+`"`)
|
checkEvalJSON(t, repl, `eth.getBalance(primary)`, `"`+testBalance+`"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSignature(t *testing.T) {
|
||||||
|
tmp, repl, ethereum := testJEthRE(t)
|
||||||
|
if err := ethereum.Start(); err != nil {
|
||||||
|
t.Errorf("error starting ethereum: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer ethereum.Stop()
|
||||||
|
defer os.RemoveAll(tmp)
|
||||||
|
|
||||||
|
val, err := repl.re.Run(`eth.sign({from: "` + testAddress + `", data: "` + testHash + `"})`)
|
||||||
|
|
||||||
|
// This is a very preliminary test, lacking actual signature verification
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error runnig js: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
output := val.String()
|
||||||
|
t.Logf("Output: %v", output)
|
||||||
|
|
||||||
|
regex := regexp.MustCompile(`^0x[0-9a-f]{130}$`)
|
||||||
|
if !regex.MatchString(output) {
|
||||||
|
t.Errorf("Signature is not 65 bytes represented in hexadecimal.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContract(t *testing.T) {
|
func TestContract(t *testing.T) {
|
||||||
|
|
||||||
tmp, repl, ethereum := testJEthRE(t)
|
tmp, repl, ethereum := testJEthRE(t)
|
||||||
|
|
|
||||||
|
|
@ -44,12 +44,6 @@ func CurrencyToString(num *big.Int) string {
|
||||||
)
|
)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case num.Cmp(Douglas) >= 0:
|
|
||||||
fin = new(big.Int).Div(num, Douglas)
|
|
||||||
denom = "Douglas"
|
|
||||||
case num.Cmp(Einstein) >= 0:
|
|
||||||
fin = new(big.Int).Div(num, Einstein)
|
|
||||||
denom = "Einstein"
|
|
||||||
case num.Cmp(Ether) >= 0:
|
case num.Cmp(Ether) >= 0:
|
||||||
fin = new(big.Int).Div(num, Ether)
|
fin = new(big.Int).Div(num, Ether)
|
||||||
denom = "Ether"
|
denom = "Ether"
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ func (s *SizeSuite) TestStorageSizeString(c *checker.C) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CommonSuite) TestCommon(c *checker.C) {
|
func (s *CommonSuite) TestCommon(c *checker.C) {
|
||||||
douglas := CurrencyToString(BigPow(10, 43))
|
|
||||||
einstein := CurrencyToString(BigPow(10, 22))
|
|
||||||
ether := CurrencyToString(BigPow(10, 19))
|
ether := CurrencyToString(BigPow(10, 19))
|
||||||
finney := CurrencyToString(BigPow(10, 16))
|
finney := CurrencyToString(BigPow(10, 16))
|
||||||
szabo := CurrencyToString(BigPow(10, 13))
|
szabo := CurrencyToString(BigPow(10, 13))
|
||||||
|
|
@ -35,8 +33,6 @@ func (s *CommonSuite) TestCommon(c *checker.C) {
|
||||||
ada := CurrencyToString(BigPow(10, 4))
|
ada := CurrencyToString(BigPow(10, 4))
|
||||||
wei := CurrencyToString(big.NewInt(10))
|
wei := CurrencyToString(big.NewInt(10))
|
||||||
|
|
||||||
c.Assert(douglas, checker.Equals, "10 Douglas")
|
|
||||||
c.Assert(einstein, checker.Equals, "10 Einstein")
|
|
||||||
c.Assert(ether, checker.Equals, "10 Ether")
|
c.Assert(ether, checker.Equals, "10 Ether")
|
||||||
c.Assert(finney, checker.Equals, "10 Finney")
|
c.Assert(finney, checker.Equals, "10 Finney")
|
||||||
c.Assert(szabo, checker.Equals, "10 Szabo")
|
c.Assert(szabo, checker.Equals, "10 Szabo")
|
||||||
|
|
@ -45,13 +41,3 @@ func (s *CommonSuite) TestCommon(c *checker.C) {
|
||||||
c.Assert(ada, checker.Equals, "10 Ada")
|
c.Assert(ada, checker.Equals, "10 Ada")
|
||||||
c.Assert(wei, checker.Equals, "10 Wei")
|
c.Assert(wei, checker.Equals, "10 Wei")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *CommonSuite) TestLarge(c *checker.C) {
|
|
||||||
douglaslarge := CurrencyToString(BigPow(100000000, 43))
|
|
||||||
adalarge := CurrencyToString(BigPow(100000000, 4))
|
|
||||||
weilarge := CurrencyToString(big.NewInt(100000000))
|
|
||||||
|
|
||||||
c.Assert(douglaslarge, checker.Equals, "10000E298 Douglas")
|
|
||||||
c.Assert(adalarge, checker.Equals, "10000E7 Einstein")
|
|
||||||
c.Assert(weilarge, checker.Equals, "100 Babbage")
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TxPreEvent is posted when a transaction enters the transaction pool.
|
// TxPreEvent is posted when a transaction enters the transaction pool.
|
||||||
|
|
@ -44,6 +46,8 @@ type ChainUncleEvent struct {
|
||||||
|
|
||||||
type ChainHeadEvent struct{ Block *types.Block }
|
type ChainHeadEvent struct{ Block *types.Block }
|
||||||
|
|
||||||
|
type GasPriceChanged struct{ Price *big.Int }
|
||||||
|
|
||||||
// Mining operation events
|
// Mining operation events
|
||||||
type StartMining struct{}
|
type StartMining struct{}
|
||||||
type TopMining struct{}
|
type TopMining struct{}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
|
AccountManager() *accounts.Manager
|
||||||
BlockProcessor() *BlockProcessor
|
BlockProcessor() *BlockProcessor
|
||||||
ChainManager() *ChainManager
|
ChainManager() *ChainManager
|
||||||
TxPool() *TxPool
|
TxPool() *TxPool
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ var (
|
||||||
ErrInvalidSender = errors.New("Invalid sender")
|
ErrInvalidSender = errors.New("Invalid sender")
|
||||||
ErrNonce = errors.New("Nonce too low")
|
ErrNonce = errors.New("Nonce too low")
|
||||||
ErrBalance = errors.New("Insufficient balance")
|
ErrBalance = errors.New("Insufficient balance")
|
||||||
ErrNonExistentAccount = errors.New("Account does not exist")
|
ErrNonExistentAccount = errors.New("Account does not exist or account balance too low")
|
||||||
ErrInsufficientFunds = errors.New("Insufficient funds for gas * price + value")
|
ErrInsufficientFunds = errors.New("Insufficient funds for gas * price + value")
|
||||||
ErrIntrinsicGas = errors.New("Intrinsic gas too low")
|
ErrIntrinsicGas = errors.New("Intrinsic gas too low")
|
||||||
ErrGasLimit = errors.New("Exceeds block gas limit")
|
ErrGasLimit = errors.New("Exceeds block gas limit")
|
||||||
|
|
|
||||||
|
|
@ -451,6 +451,8 @@ func (s *Ethereum) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sync databases every minute. If flushing fails we exit immediatly. The system
|
||||||
|
// may not continue under any circumstances.
|
||||||
func (s *Ethereum) syncDatabases() {
|
func (s *Ethereum) syncDatabases() {
|
||||||
ticker := time.NewTicker(1 * time.Minute)
|
ticker := time.NewTicker(1 * time.Minute)
|
||||||
done:
|
done:
|
||||||
|
|
@ -459,13 +461,13 @@ done:
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
// don't change the order of database flushes
|
// don't change the order of database flushes
|
||||||
if err := s.extraDb.Flush(); err != nil {
|
if err := s.extraDb.Flush(); err != nil {
|
||||||
glog.V(logger.Error).Infof("error: flush extraDb: %v\n", err)
|
glog.Fatalf("fatal error: flush extraDb: %v\n", err)
|
||||||
}
|
}
|
||||||
if err := s.stateDb.Flush(); err != nil {
|
if err := s.stateDb.Flush(); err != nil {
|
||||||
glog.V(logger.Error).Infof("error: flush stateDb: %v\n", err)
|
glog.Fatalf("fatal error: flush stateDb: %v\n", err)
|
||||||
}
|
}
|
||||||
if err := s.blockDb.Flush(); err != nil {
|
if err := s.blockDb.Flush(); err != nil {
|
||||||
glog.V(logger.Error).Infof("error: flush blockDb: %v\n", err)
|
glog.Fatalf("fatal error: flush blockDb: %v\n", err)
|
||||||
}
|
}
|
||||||
case <-s.shutdownChan:
|
case <-s.shutdownChan:
|
||||||
break done
|
break done
|
||||||
|
|
|
||||||
3692
jsre/ethereum_js.go
3692
jsre/ethereum_js.go
File diff suppressed because one or more lines are too long
|
|
@ -7,6 +7,8 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -47,6 +49,8 @@ func (m *Miner) SetGasPrice(price *big.Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) Start(coinbase common.Address) {
|
func (self *Miner) Start(coinbase common.Address) {
|
||||||
|
glog.V(logger.Info).Infoln("Starting mining operation")
|
||||||
|
|
||||||
self.mining = true
|
self.mining = true
|
||||||
self.worker.coinbase = coinbase
|
self.worker.coinbase = coinbase
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
|
||||||
188
miner/worker.go
188
miner/worker.go
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
|
@ -21,12 +22,18 @@ import (
|
||||||
var jsonlogger = logger.NewJsonLogger()
|
var jsonlogger = logger.NewJsonLogger()
|
||||||
|
|
||||||
type environment struct {
|
type environment struct {
|
||||||
totalUsedGas *big.Int
|
totalUsedGas *big.Int
|
||||||
state *state.StateDB
|
state *state.StateDB
|
||||||
coinbase *state.StateObject
|
coinbase *state.StateObject
|
||||||
block *types.Block
|
block *types.Block
|
||||||
family *set.Set
|
family *set.Set
|
||||||
uncles *set.Set
|
uncles *set.Set
|
||||||
|
remove *set.Set
|
||||||
|
tcount int
|
||||||
|
ignoredTransactors *set.Set
|
||||||
|
lowGasTransactors *set.Set
|
||||||
|
ownedAccounts *set.Set
|
||||||
|
lowGasTxs types.Transactions
|
||||||
}
|
}
|
||||||
|
|
||||||
func env(block *types.Block, eth core.Backend) *environment {
|
func env(block *types.Block, eth core.Backend) *environment {
|
||||||
|
|
@ -128,12 +135,13 @@ func (self *worker) start() {
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
defer self.mu.Unlock()
|
defer self.mu.Unlock()
|
||||||
|
|
||||||
|
atomic.StoreInt32(&self.mining, 1)
|
||||||
|
|
||||||
// spin up agents
|
// spin up agents
|
||||||
for _, agent := range self.agents {
|
for _, agent := range self.agents {
|
||||||
agent.Start()
|
agent.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic.StoreInt32(&self.mining, 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) stop() {
|
func (self *worker) stop() {
|
||||||
|
|
@ -174,8 +182,11 @@ out:
|
||||||
self.possibleUncles[ev.Block.Hash()] = ev.Block
|
self.possibleUncles[ev.Block.Hash()] = ev.Block
|
||||||
self.uncleMu.Unlock()
|
self.uncleMu.Unlock()
|
||||||
case core.TxPreEvent:
|
case core.TxPreEvent:
|
||||||
|
// Apply transaction to the pending state if we're not mining
|
||||||
if atomic.LoadInt32(&self.mining) == 0 {
|
if atomic.LoadInt32(&self.mining) == 0 {
|
||||||
self.commitNewWork()
|
self.mu.Lock()
|
||||||
|
self.commitTransactions(types.Transactions{ev.Tx})
|
||||||
|
self.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case <-self.quit:
|
case <-self.quit:
|
||||||
|
|
@ -241,19 +252,33 @@ func (self *worker) makeCurrent() {
|
||||||
}
|
}
|
||||||
block.Header().Extra = self.extra
|
block.Header().Extra = self.extra
|
||||||
|
|
||||||
self.current = env(block, self.eth)
|
current := env(block, self.eth)
|
||||||
for _, ancestor := range self.chain.GetAncestors(block, 7) {
|
for _, ancestor := range self.chain.GetAncestors(block, 7) {
|
||||||
self.current.family.Add(ancestor.Hash())
|
current.family.Add(ancestor.Hash())
|
||||||
}
|
}
|
||||||
|
accounts, _ := self.eth.AccountManager().Accounts()
|
||||||
|
// Keep track of transactions which return errors so they can be removed
|
||||||
|
current.remove = set.New()
|
||||||
|
current.tcount = 0
|
||||||
|
current.ignoredTransactors = set.New()
|
||||||
|
current.lowGasTransactors = set.New()
|
||||||
|
current.ownedAccounts = accountAddressesSet(accounts)
|
||||||
|
|
||||||
parent := self.chain.GetBlock(self.current.block.ParentHash())
|
parent := self.chain.GetBlock(current.block.ParentHash())
|
||||||
self.current.coinbase.SetGasPool(core.CalcGasLimit(parent))
|
current.coinbase.SetGasPool(core.CalcGasLimit(parent))
|
||||||
|
|
||||||
|
self.current = current
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *worker) setGasPrice(p *big.Int) {
|
func (w *worker) setGasPrice(p *big.Int) {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
w.gasPrice = p
|
|
||||||
|
// calculate the minimal gas price the miner accepts when sorting out transactions.
|
||||||
|
const pct = int64(90)
|
||||||
|
w.gasPrice = gasprice(p, pct)
|
||||||
|
|
||||||
|
w.mux.Post(core.GasPriceChanged{w.gasPrice})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) commitNewWork() {
|
func (self *worker) commitNewWork() {
|
||||||
|
|
@ -265,68 +290,14 @@ func (self *worker) commitNewWork() {
|
||||||
defer self.currentMu.Unlock()
|
defer self.currentMu.Unlock()
|
||||||
|
|
||||||
self.makeCurrent()
|
self.makeCurrent()
|
||||||
|
current := self.current
|
||||||
|
|
||||||
transactions := self.eth.TxPool().GetTransactions()
|
transactions := self.eth.TxPool().GetTransactions()
|
||||||
sort.Sort(types.TxByNonce{transactions})
|
sort.Sort(types.TxByNonce{transactions})
|
||||||
|
|
||||||
// Keep track of transactions which return errors so they can be removed
|
// commit transactions for this run
|
||||||
var (
|
self.commitTransactions(transactions)
|
||||||
remove = set.New()
|
self.eth.TxPool().RemoveTransactions(current.lowGasTxs)
|
||||||
tcount = 0
|
|
||||||
ignoredTransactors = set.New()
|
|
||||||
)
|
|
||||||
|
|
||||||
const pct = int64(90)
|
|
||||||
// calculate the minimal gas price the miner accepts when sorting out transactions.
|
|
||||||
minprice := gasprice(self.gasPrice, pct)
|
|
||||||
for _, tx := range transactions {
|
|
||||||
// We can skip err. It has already been validated in the tx pool
|
|
||||||
from, _ := tx.From()
|
|
||||||
|
|
||||||
// check if it falls within margin
|
|
||||||
if tx.GasPrice().Cmp(minprice) < 0 {
|
|
||||||
// ignore the transaction and transactor. We ignore the transactor
|
|
||||||
// because nonce will fail after ignoring this transaction so there's
|
|
||||||
// no point
|
|
||||||
ignoredTransactors.Add(from)
|
|
||||||
glog.V(logger.Info).Infof("transaction(%x) below gas price (<%d%% ask price). All sequential txs from this address(%x) will fail\n", tx.Hash().Bytes()[:4], pct, from[:4])
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move on to the next transaction when the transactor is in ignored transactions set
|
|
||||||
// This may occur when a transaction hits the gas limit. When a gas limit is hit and
|
|
||||||
// the transaction is processed (that could potentially be included in the block) it
|
|
||||||
// will throw a nonce error because the previous transaction hasn't been processed.
|
|
||||||
// Therefor we need to ignore any transaction after the ignored one.
|
|
||||||
if ignoredTransactors.Has(from) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
self.current.state.StartRecord(tx.Hash(), common.Hash{}, 0)
|
|
||||||
|
|
||||||
err := self.commitTransaction(tx)
|
|
||||||
switch {
|
|
||||||
case core.IsNonceErr(err) || core.IsInvalidTxErr(err):
|
|
||||||
// Remove invalid transactions
|
|
||||||
from, _ := tx.From()
|
|
||||||
|
|
||||||
self.chain.TxState().RemoveNonce(from, tx.Nonce())
|
|
||||||
remove.Add(tx.Hash())
|
|
||||||
|
|
||||||
if glog.V(logger.Detail) {
|
|
||||||
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
|
|
||||||
}
|
|
||||||
case state.IsGasLimitErr(err):
|
|
||||||
from, _ := tx.From()
|
|
||||||
// ignore the transactor so no nonce errors will be thrown for this account
|
|
||||||
// next time the worker is run, they'll be picked up again.
|
|
||||||
ignoredTransactors.Add(from)
|
|
||||||
|
|
||||||
glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])
|
|
||||||
default:
|
|
||||||
tcount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uncles []*types.Header
|
uncles []*types.Header
|
||||||
|
|
@ -352,7 +323,7 @@ func (self *worker) commitNewWork() {
|
||||||
|
|
||||||
// We only care about logging if we're actually mining
|
// We only care about logging if we're actually mining
|
||||||
if atomic.LoadInt32(&self.mining) == 1 {
|
if atomic.LoadInt32(&self.mining) == 1 {
|
||||||
glog.V(logger.Info).Infof("commit new work on block %v with %d txs & %d uncles\n", self.current.block.Number(), tcount, len(uncles))
|
glog.V(logger.Info).Infof("commit new work on block %v with %d txs & %d uncles\n", current.block.Number(), current.tcount, len(uncles))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hash := range badUncles {
|
for _, hash := range badUncles {
|
||||||
|
|
@ -392,6 +363,71 @@ func (self *worker) commitUncle(uncle *types.Header) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *worker) commitTransactions(transactions types.Transactions) {
|
||||||
|
current := self.current
|
||||||
|
|
||||||
|
for _, tx := range transactions {
|
||||||
|
// We can skip err. It has already been validated in the tx pool
|
||||||
|
from, _ := tx.From()
|
||||||
|
|
||||||
|
// check if it falls within margin
|
||||||
|
if tx.GasPrice().Cmp(self.gasPrice) < 0 {
|
||||||
|
// ignore the transaction and transactor. We ignore the transactor
|
||||||
|
// because nonce will fail after ignoring this transaction so there's
|
||||||
|
// no point
|
||||||
|
current.lowGasTransactors.Add(from)
|
||||||
|
|
||||||
|
glog.V(logger.Info).Infof("transaction(%x) below gas price (tx=%v ask=%v). All sequential txs from this address(%x) will be ignored\n", tx.Hash().Bytes()[:4], common.CurrencyToString(tx.GasPrice()), common.CurrencyToString(self.gasPrice), from[:4])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continue with the next transaction if the transaction sender is included in
|
||||||
|
// the low gas tx set. This will also remove the tx and all sequential transaction
|
||||||
|
// from this transactor
|
||||||
|
if current.lowGasTransactors.Has(from) {
|
||||||
|
// add tx to the low gas set. This will be removed at the end of the run
|
||||||
|
// owned accounts are ignored
|
||||||
|
if !current.ownedAccounts.Has(from) {
|
||||||
|
current.lowGasTxs = append(current.lowGasTxs, tx)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move on to the next transaction when the transactor is in ignored transactions set
|
||||||
|
// This may occur when a transaction hits the gas limit. When a gas limit is hit and
|
||||||
|
// the transaction is processed (that could potentially be included in the block) it
|
||||||
|
// will throw a nonce error because the previous transaction hasn't been processed.
|
||||||
|
// Therefor we need to ignore any transaction after the ignored one.
|
||||||
|
if current.ignoredTransactors.Has(from) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
self.current.state.StartRecord(tx.Hash(), common.Hash{}, 0)
|
||||||
|
|
||||||
|
err := self.commitTransaction(tx)
|
||||||
|
switch {
|
||||||
|
case core.IsNonceErr(err) || core.IsInvalidTxErr(err):
|
||||||
|
// Remove invalid transactions
|
||||||
|
from, _ := tx.From()
|
||||||
|
|
||||||
|
self.chain.TxState().RemoveNonce(from, tx.Nonce())
|
||||||
|
current.remove.Add(tx.Hash())
|
||||||
|
|
||||||
|
if glog.V(logger.Detail) {
|
||||||
|
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
|
||||||
|
}
|
||||||
|
case state.IsGasLimitErr(err):
|
||||||
|
from, _ := tx.From()
|
||||||
|
// ignore the transactor so no nonce errors will be thrown for this account
|
||||||
|
// next time the worker is run, they'll be picked up again.
|
||||||
|
current.ignoredTransactors.Add(from)
|
||||||
|
|
||||||
|
glog.V(logger.Detail).Infof("Gas limit reached for (%x) in this block. Continue to try smaller txs\n", from[:4])
|
||||||
|
default:
|
||||||
|
current.tcount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *worker) commitTransaction(tx *types.Transaction) error {
|
func (self *worker) commitTransaction(tx *types.Transaction) error {
|
||||||
snap := self.current.state.Copy()
|
snap := self.current.state.Copy()
|
||||||
receipt, _, err := self.proc.ApplyTransaction(self.current.coinbase, self.current.state, self.current.block, tx, self.current.totalUsedGas, true)
|
receipt, _, err := self.proc.ApplyTransaction(self.current.coinbase, self.current.state, self.current.block, tx, self.current.totalUsedGas, true)
|
||||||
|
|
@ -423,3 +459,11 @@ func gasprice(price *big.Int, pct int64) *big.Int {
|
||||||
p.Mul(p, big.NewInt(pct))
|
p.Mul(p, big.NewInt(pct))
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func accountAddressesSet(accounts []accounts.Account) *set.Set {
|
||||||
|
accountSet := set.New()
|
||||||
|
for _, account := range accounts {
|
||||||
|
accountSet.Add(common.BytesToAddress(account.Address))
|
||||||
|
}
|
||||||
|
return accountSet
|
||||||
|
}
|
||||||
|
|
|
||||||
44
rpc/api.go
44
rpc/api.go
|
|
@ -158,6 +158,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
v := api.xethAtStateNum(args.BlockNumber).CodeAtBytes(args.Address)
|
v := api.xethAtStateNum(args.BlockNumber).CodeAtBytes(args.Address)
|
||||||
*reply = newHexData(v)
|
*reply = newHexData(v)
|
||||||
|
|
||||||
|
case "eth_sign":
|
||||||
|
args := new(NewSigArgs)
|
||||||
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
v, err := api.xeth().Sign(args.From, args.Data, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*reply = v
|
||||||
|
|
||||||
case "eth_sendTransaction", "eth_transact":
|
case "eth_sendTransaction", "eth_transact":
|
||||||
args := new(NewTxArgs)
|
args := new(NewTxArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
@ -439,10 +450,18 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
*reply = newHexData(res)
|
*reply = newHexData(res)
|
||||||
|
|
||||||
case "shh_version":
|
case "shh_version":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Retrieves the currently running whisper protocol version
|
// Retrieves the currently running whisper protocol version
|
||||||
*reply = api.xeth().WhisperVersion()
|
*reply = api.xeth().WhisperVersion()
|
||||||
|
|
||||||
case "shh_post":
|
case "shh_post":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Injects a new message into the whisper network
|
// Injects a new message into the whisper network
|
||||||
args := new(WhisperMessageArgs)
|
args := new(WhisperMessageArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
@ -455,10 +474,18 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
*reply = true
|
*reply = true
|
||||||
|
|
||||||
case "shh_newIdentity":
|
case "shh_newIdentity":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Creates a new whisper identity to use for sending/receiving messages
|
// Creates a new whisper identity to use for sending/receiving messages
|
||||||
*reply = api.xeth().Whisper().NewIdentity()
|
*reply = api.xeth().Whisper().NewIdentity()
|
||||||
|
|
||||||
case "shh_hasIdentity":
|
case "shh_hasIdentity":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Checks if an identity if owned or not
|
// Checks if an identity if owned or not
|
||||||
args := new(WhisperIdentityArgs)
|
args := new(WhisperIdentityArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
@ -467,6 +494,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
*reply = api.xeth().Whisper().HasIdentity(args.Identity)
|
*reply = api.xeth().Whisper().HasIdentity(args.Identity)
|
||||||
|
|
||||||
case "shh_newFilter":
|
case "shh_newFilter":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Create a new filter to watch and match messages with
|
// Create a new filter to watch and match messages with
|
||||||
args := new(WhisperFilterArgs)
|
args := new(WhisperFilterArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
@ -476,6 +507,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
*reply = newHexNum(big.NewInt(int64(id)).Bytes())
|
*reply = newHexNum(big.NewInt(int64(id)).Bytes())
|
||||||
|
|
||||||
case "shh_uninstallFilter":
|
case "shh_uninstallFilter":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Remove an existing filter watching messages
|
// Remove an existing filter watching messages
|
||||||
args := new(FilterIdArgs)
|
args := new(FilterIdArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
@ -484,6 +519,10 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
*reply = api.xeth().UninstallWhisperFilter(args.Id)
|
*reply = api.xeth().UninstallWhisperFilter(args.Id)
|
||||||
|
|
||||||
case "shh_getFilterChanges":
|
case "shh_getFilterChanges":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Retrieve all the new messages arrived since the last request
|
// Retrieve all the new messages arrived since the last request
|
||||||
args := new(FilterIdArgs)
|
args := new(FilterIdArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
@ -492,12 +531,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
||||||
*reply = api.xeth().WhisperMessagesChanged(args.Id)
|
*reply = api.xeth().WhisperMessagesChanged(args.Id)
|
||||||
|
|
||||||
case "shh_getMessages":
|
case "shh_getMessages":
|
||||||
|
// Short circuit if whisper is not running
|
||||||
|
if api.xeth().Whisper() == nil {
|
||||||
|
return NewNotAvailableError(req.Method, "whisper offline")
|
||||||
|
}
|
||||||
// Retrieve all the cached messages matching a specific, existing filter
|
// Retrieve all the cached messages matching a specific, existing filter
|
||||||
args := new(FilterIdArgs)
|
args := new(FilterIdArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = api.xeth().WhisperMessages(args.Id)
|
*reply = api.xeth().WhisperMessages(args.Id)
|
||||||
|
|
||||||
case "eth_hashrate":
|
case "eth_hashrate":
|
||||||
*reply = newHexNum(api.xeth().HashRate())
|
*reply = newHexNum(api.xeth().HashRate())
|
||||||
|
|
||||||
|
|
|
||||||
40
rpc/args.go
40
rpc/args.go
|
|
@ -166,6 +166,46 @@ type NewTxArgs struct {
|
||||||
BlockNumber int64
|
BlockNumber int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NewSigArgs struct {
|
||||||
|
From string
|
||||||
|
Data string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) {
|
||||||
|
var obj []json.RawMessage
|
||||||
|
var ext struct {
|
||||||
|
From string
|
||||||
|
Data string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode byte slice to array of RawMessages
|
||||||
|
if err := json.Unmarshal(b, &obj); err != nil {
|
||||||
|
return NewDecodeParamError(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for sufficient params
|
||||||
|
if len(obj) < 1 {
|
||||||
|
return NewInsufficientParamsError(len(obj), 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decode 0th RawMessage to temporary struct
|
||||||
|
if err := json.Unmarshal(obj[0], &ext); err != nil {
|
||||||
|
return NewDecodeParamError(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ext.From) == 0 {
|
||||||
|
return NewValidationError("from", "is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(ext.Data) == 0 {
|
||||||
|
return NewValidationError("data", "is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
args.From = ext.From
|
||||||
|
args.Data = ext.Data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
||||||
var obj []json.RawMessage
|
var obj []json.RawMessage
|
||||||
var ext struct {
|
var ext struct {
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func RpcResponse(api *EthereumApi, request *RpcRequest) *interface{} {
|
||||||
switch reserr.(type) {
|
switch reserr.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
response = &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: request.Id, Result: reply}
|
response = &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: request.Id, Result: reply}
|
||||||
case *NotImplementedError:
|
case *NotImplementedError, *NotAvailableError:
|
||||||
jsonerr := &RpcErrorObject{-32601, reserr.Error()}
|
jsonerr := &RpcErrorObject{-32601, reserr.Error()}
|
||||||
response = &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: request.Id, Error: jsonerr}
|
response = &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: request.Id, Error: jsonerr}
|
||||||
case *DecodeParamError, *InsufficientParamsError, *ValidationError, *InvalidTypeError:
|
case *DecodeParamError, *InsufficientParamsError, *ValidationError, *InvalidTypeError:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"github.com/ethereum/go-ethereum/jsre"
|
"github.com/ethereum/go-ethereum/jsre"
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
@ -35,7 +35,6 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonreq, err := json.Marshal(reqif)
|
jsonreq, err := json.Marshal(reqif)
|
||||||
|
|
||||||
var reqs []RpcRequest
|
var reqs []RpcRequest
|
||||||
batch := true
|
batch := true
|
||||||
err = json.Unmarshal(jsonreq, &reqs)
|
err = json.Unmarshal(jsonreq, &reqs)
|
||||||
|
|
@ -52,6 +51,7 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
|
||||||
var respif interface{}
|
var respif interface{}
|
||||||
err = self.ethApi.GetRequestReply(&req, &respif)
|
err = self.ethApi.GetRequestReply(&req, &respif)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Error response:", err)
|
||||||
return self.err(call, -32603, err.Error(), req.Id)
|
return self.err(call, -32603, err.Error(), req.Id)
|
||||||
}
|
}
|
||||||
call.Otto.Set("ret_jsonrpc", jsonrpcver)
|
call.Otto.Set("ret_jsonrpc", jsonrpcver)
|
||||||
|
|
|
||||||
16
rpc/types.go
16
rpc/types.go
|
|
@ -209,6 +209,22 @@ func NewNotImplementedError(method string) *NotImplementedError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NotAvailableError struct {
|
||||||
|
Method string
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *NotAvailableError) Error() string {
|
||||||
|
return fmt.Sprintf("%s method not available: %s", e.Method, e.Reason)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewNotAvailableError(method string, reason string) *NotAvailableError {
|
||||||
|
return &NotAvailableError{
|
||||||
|
Method: method,
|
||||||
|
Reason: reason,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type DecodeParamError struct {
|
type DecodeParamError struct {
|
||||||
err string
|
err string
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
xeth/xeth.go
25
xeth/xeth.go
|
|
@ -79,7 +79,6 @@ func New(eth *eth.Ethereum, frontend Frontend) *XEth {
|
||||||
xeth := &XEth{
|
xeth := &XEth{
|
||||||
backend: eth,
|
backend: eth,
|
||||||
frontend: frontend,
|
frontend: frontend,
|
||||||
whisper: NewWhisper(eth.Whisper()),
|
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
filterManager: filter.NewFilterManager(eth.EventMux()),
|
filterManager: filter.NewFilterManager(eth.EventMux()),
|
||||||
logQueue: make(map[int]*logQueue),
|
logQueue: make(map[int]*logQueue),
|
||||||
|
|
@ -88,6 +87,9 @@ func New(eth *eth.Ethereum, frontend Frontend) *XEth {
|
||||||
messages: make(map[int]*whisperFilter),
|
messages: make(map[int]*whisperFilter),
|
||||||
agent: miner.NewRemoteAgent(),
|
agent: miner.NewRemoteAgent(),
|
||||||
}
|
}
|
||||||
|
if eth.Whisper() != nil {
|
||||||
|
xeth.whisper = NewWhisper(eth.Whisper())
|
||||||
|
}
|
||||||
eth.Miner().Register(xeth.agent)
|
eth.Miner().Register(xeth.agent)
|
||||||
if frontend == nil {
|
if frontend == nil {
|
||||||
xeth.frontend = dummyFrontend{}
|
xeth.frontend = dummyFrontend{}
|
||||||
|
|
@ -813,6 +815,27 @@ func (self *XEth) ConfirmTransaction(tx string) bool {
|
||||||
return self.frontend.ConfirmTransaction(tx)
|
return self.frontend.ConfirmTransaction(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *XEth) Sign(fromStr, hashStr string, didUnlock bool) (string, error) {
|
||||||
|
var (
|
||||||
|
from = common.HexToAddress(fromStr)
|
||||||
|
hash = common.HexToHash(hashStr)
|
||||||
|
)
|
||||||
|
sig, err := self.backend.AccountManager().Sign(accounts.Account{Address: from.Bytes()}, hash.Bytes())
|
||||||
|
if err == accounts.ErrLocked {
|
||||||
|
if didUnlock {
|
||||||
|
return "", fmt.Errorf("signer account still locked after successful unlock")
|
||||||
|
}
|
||||||
|
if !self.frontend.UnlockAccount(from.Bytes()) {
|
||||||
|
return "", fmt.Errorf("could not unlock signer account")
|
||||||
|
}
|
||||||
|
// retry signing, the account should now be unlocked.
|
||||||
|
return self.Sign(fromStr, hashStr, true)
|
||||||
|
} else if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return common.ToHex(sig), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
|
func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
|
||||||
|
|
||||||
// this minimalistic recoding is enough (works for natspec.js)
|
// this minimalistic recoding is enough (works for natspec.js)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue