nearly done

This commit is contained in:
BatuhanHU 2020-01-13 17:23:10 +03:00
parent 9b5d31474f
commit 2ef8510ba6
26 changed files with 235 additions and 60 deletions

View file

@ -455,6 +455,8 @@ func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas } func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value } func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data } func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) Payer() []byte { return m.CallMsg.Payer }
// filterBackend implements filters.Backend to support filtering for logs without // filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account. // taking bloom-bits acceleration structures into account.

5
chainready.sh Executable file
View file

@ -0,0 +1,5 @@
rm -rf ../newcoin_data
mkdir ../newcoin_data
./build/bin/geth init --datadir ../newcoin_data/ genesis.json
./build/bin/geth --datadir ../newcoin_data --rpc --rpcapi txpool --rpcport 8545 --mine --miner.threads=1 --etherbase=0x4d058e24aEC4d7Ce5341641931c73936F313862D console

View file

@ -451,6 +451,8 @@ func (api *RetestethAPI) MineBlocks(ctx context.Context, number uint64) (bool, e
} }
func (api *RetestethAPI) mineBlock() error { func (api *RetestethAPI) mineBlock() error {
log.Info("mineBlock")
parentHash := rawdb.ReadCanonicalHash(api.ethDb, api.blockNumber) parentHash := rawdb.ReadCanonicalHash(api.ethDb, api.blockNumber)
parent := rawdb.ReadBlock(api.ethDb, parentHash, api.blockNumber) parent := rawdb.ReadBlock(api.ethDb, parentHash, api.blockNumber)
var timestamp uint64 var timestamp uint64
@ -618,6 +620,7 @@ func (api *RetestethAPI) AccountRange(ctx context.Context,
blockHashOrNumber *math.HexOrDecimal256, txIndex uint64, blockHashOrNumber *math.HexOrDecimal256, txIndex uint64,
addressHash *math.HexOrDecimal256, maxResults uint64, addressHash *math.HexOrDecimal256, maxResults uint64,
) (AccountRangeResult, error) { ) (AccountRangeResult, error) {
log.Info("AccountRrange")
var ( var (
header *types.Header header *types.Header
block *types.Block block *types.Block
@ -729,6 +732,7 @@ func (api *RetestethAPI) StorageRangeAt(ctx context.Context,
address common.Address, address common.Address,
begin *math.HexOrDecimal256, maxResults uint64, begin *math.HexOrDecimal256, maxResults uint64,
) (StorageRangeResult, error) { ) (StorageRangeResult, error) {
log.Info("StorageRangeAt")
var ( var (
header *types.Header header *types.Header
block *types.Block block *types.Block

View file

@ -33,9 +33,8 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
) )
const ( const (
@ -149,13 +148,15 @@ func (ethash *Ethash) mine(block *types.Block, id int, seed uint64, abort chan s
attempts = int64(0) attempts = int64(0)
nonce = seed nonce = seed
) )
if len(block.Transactions()) < 1 {
if len(block.Transactions()) < 1 {
log.Info("No txs") log.Info("No txs")
log.Info("Lel","asd",crypto.VerifySignature([]byte("376fc429acc35e610f75b14bc96242b13623833569a5bb3d72c17be7e51da0bb58e48e2462a59897cead8ab88e78709f9d24fd6ec24d1456f43aae407a8970e4"), log.Info("Lel", "asd", crypto.VerifySignature([]byte("376fc429acc35e610f75b14bc96242b13623833569a5bb3d72c17be7e51da0bb58e48e2462a59897cead8ab88e78709f9d24fd6ec24d1456f43aae407a8970e4"),
[]byte("5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060"),[]byte("cdffeff8feff9cffee15dbeffe5ffdb7ffdbb7f6bfffdcaffbedb74e4f3ff3fa"))) []byte("5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060"), []byte("cdffeff8feff9cffee15dbeffe5ffdb7ffdbb7f6bfffdcaffbedb74e4f3ff3fa")))
return return
} }
log.Info("TX varmis la ")
logger := log.New("miner", id) logger := log.New("miner", id)
logger.Trace("Started ethash search for new nonces", "seed", seed) logger.Trace("Started ethash search for new nonces", "seed", seed)
search: search:

View file

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/log"
) )
// BlockGen creates blocks for testing. // BlockGen creates blocks for testing.
@ -99,6 +100,8 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
// added. If contract code relies on the BLOCKHASH instruction, // added. If contract code relies on the BLOCKHASH instruction,
// the block in chain will be returned. // the block in chain will be returned.
func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) { func (b *BlockGen) AddTxWithChain(bc *BlockChain, tx *types.Transaction) {
log.Info("AddTxWithChain")
if b.gasPool == nil { if b.gasPool == nil {
b.SetCoinbase(common.Address{}) b.SetCoinbase(common.Address{})
} }

View file

@ -65,6 +65,7 @@ func WriteTxLookupEntries(db ethdb.KeyValueWriter, block *types.Block) {
// DeleteTxLookupEntry removes all transaction data associated with a hash. // DeleteTxLookupEntry removes all transaction data associated with a hash.
func DeleteTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash) { func DeleteTxLookupEntry(db ethdb.KeyValueWriter, hash common.Hash) {
log.Info("DeleteTxLookupEntry")
db.Delete(txLookupKey(hash)) db.Delete(txLookupKey(hash))
} }

View file

@ -24,6 +24,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
@ -350,10 +351,12 @@ func (s *stateObject) AddBalance(amount *big.Int) {
// SubBalance removes amount from c's balance. // SubBalance removes amount from c's balance.
// It is used to remove funds from the origin account of a transfer. // It is used to remove funds from the origin account of a transfer.
func (s *stateObject) SubBalance(amount *big.Int) { func (s *stateObject) SubBalance(amount *big.Int) {
log.Info("I am at sub Balance")
if amount.Sign() == 0 { if amount.Sign() == 0 {
return return
} }
s.SetBalance(new(big.Int).Sub(s.Balance(), amount)) s.SetBalance(new(big.Int).Sub(s.Balance(), amount))
log.Info("Balance subbed")
} }
func (s *stateObject) SetBalance(amount *big.Int) { func (s *stateObject) SetBalance(amount *big.Int) {

View file

@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/log"
) )
// statePrefetcher is a basic Prefetcher, which blindly executes a block on top // statePrefetcher is a basic Prefetcher, which blindly executes a block on top
@ -79,6 +80,7 @@ func precacheTransaction(config *params.ChainConfig, bc ChainContext, author *co
// Create the EVM and execute the transaction // Create the EVM and execute the transaction
context := NewEVMContext(msg, header, bc, author) context := NewEVMContext(msg, header, bc, author)
vm := vm.NewEVM(context, statedb, config, cfg) vm := vm.NewEVM(context, statedb, config, cfg)
log.Info("precacheTransaction")
_, _, _, err = ApplyMessage(vm, msg, gaspool) _, _, _, err = ApplyMessage(vm, msg, gaspool)
return err return err

View file

@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/log"
) )
// StateProcessor is a basic Processor, which takes care of transitioning // StateProcessor is a basic Processor, which takes care of transitioning
@ -54,6 +55,8 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
// returns the amount of gas that was used in the process. If any of the // returns the amount of gas that was used in the process. If any of the
// transactions failed to execute due to insufficient gas it will return an error. // transactions failed to execute due to insufficient gas it will return an error.
func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) { func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error) {
log.Info("Process")
var ( var (
receipts types.Receipts receipts types.Receipts
usedGas = new(uint64) usedGas = new(uint64)
@ -86,6 +89,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// for the transaction, gas used and an error if the transaction failed, // for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid. // indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) { func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
log.Info("ApplyTransaction")
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number)) msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -23,6 +23,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
@ -73,6 +74,7 @@ type Message interface {
Nonce() uint64 Nonce() uint64
CheckNonce() bool CheckNonce() bool
Data() []byte Data() []byte
Payer() []byte
} }
// IntrinsicGas computes the 'intrinsic gas' for a message with the given data. // IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
@ -133,6 +135,8 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
// indicates a core error meaning that the message would always fail for that particular // indicates a core error meaning that the message would always fail for that particular
// state and would never be accepted within a block. // state and would never be accepted within a block.
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) { func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) {
log.Info("Apply Message")
return NewStateTransition(evm, msg, gp).TransitionDb() return NewStateTransition(evm, msg, gp).TransitionDb()
} }
@ -155,21 +159,36 @@ func (st *StateTransition) useGas(amount uint64) error {
func (st *StateTransition) buyGas() error { func (st *StateTransition) buyGas() error {
mgval := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice) mgval := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice)
if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 { var payerAddress common.Address
if len(st.msg.Payer()) != 0 {
payerAddress = common.BytesToAddress(crypto.Keccak256(st.msg.Payer())[12:])
if st.state.GetBalance(payerAddress).Cmp(mgval) < 0 {
return errInsufficientBalanceForGas
}
} else if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 {
log.Info("I dont have money for gas i am homeless")
log.Info("homeless pil", "from money: ", st.msg.Payer())
return errInsufficientBalanceForGas return errInsufficientBalanceForGas
} }
if err := st.gp.SubGas(st.msg.Gas()); err != nil { if err := st.gp.SubGas(st.msg.Gas()); err != nil {
log.Info("I dont have money for gas i am homeless")
return err return err
} }
st.gas += st.msg.Gas() st.gas += st.msg.Gas()
st.initialGas = st.msg.Gas() st.initialGas = st.msg.Gas()
st.state.SubBalance(st.msg.From(), mgval) if len(st.msg.Payer()) != 0 {
st.state.SubBalance(payerAddress, mgval)
} else {
st.state.SubBalance(st.msg.From(), mgval)
}
return nil return nil
} }
func (st *StateTransition) preCheck() error { func (st *StateTransition) preCheck() error {
// Make sure this transaction's nonce is correct. // Make sure this transaction's nonce is correct.
if st.msg.CheckNonce() { if st.msg.CheckNonce() {
nonce := st.state.GetNonce(st.msg.From()) nonce := st.state.GetNonce(st.msg.From())
if nonce < st.msg.Nonce() { if nonce < st.msg.Nonce() {
@ -178,6 +197,8 @@ func (st *StateTransition) preCheck() error {
return ErrNonceTooLow return ErrNonceTooLow
} }
} }
log.Info("I will try to buy gas")
return st.buyGas() return st.buyGas()
} }
@ -188,13 +209,19 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
if err = st.preCheck(); err != nil { if err = st.preCheck(); err != nil {
return return
} }
log.Info("I am in transitionDB")
msg := st.msg msg := st.msg
sender := vm.AccountRef(msg.From()) sender := vm.AccountRef(msg.From())
homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber) homestead := st.evm.ChainConfig().IsHomestead(st.evm.BlockNumber)
istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.BlockNumber) istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.BlockNumber)
contractCreation := msg.To() == nil contractCreation := msg.To() == nil
payer := msg.Payer()
payerAddress := common.BytesToAddress(crypto.Keccak256(payer)[12:])
// Pay intrinsic gas // Pay intrinsic gas
log.Info("Before instrinsicGas")
gas, err := IntrinsicGas(st.data, contractCreation, homestead, istanbul) gas, err := IntrinsicGas(st.data, contractCreation, homestead, istanbul)
if err != nil { if err != nil {
return nil, 0, false, err return nil, 0, false, err
@ -214,15 +241,19 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value) ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else { } else {
// Increment the nonce for the next transaction // Increment the nonce for the next transaction
log.Info("I am in transitionDB incrementing nonce")
st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1) st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value) log.Info("Before evmCall")
ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value,payerAddress)
} }
if vmerr != nil { if vmerr != nil {
log.Info("VM returned with error", "err", vmerr)
log.Debug("VM returned with error", "err", vmerr) log.Debug("VM returned with error", "err", vmerr)
// The only possible consensus-error would be if there wasn't // The only possible consensus-error would be if there wasn't
// sufficient balance to make the transfer happen. The first // sufficient balance to make the transfer happen. The first
// balance transfer may never fail. // balance transfer may never fail.
if vmerr == vm.ErrInsufficientBalance { if vmerr == vm.ErrInsufficientBalance {
log.Info("VM insufficientBalance")
return nil, 0, false, vmerr return nil, 0, false, vmerr
} }
} }
@ -242,7 +273,13 @@ func (st *StateTransition) refundGas() {
// Return ETH for remaining gas, exchanged at the original rate. // Return ETH for remaining gas, exchanged at the original rate.
remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gas), st.gasPrice) remaining := new(big.Int).Mul(new(big.Int).SetUint64(st.gas), st.gasPrice)
st.state.AddBalance(st.msg.From(), remaining)
if(len(msg.Payer)!= 0) {
payer := msg.Payer()
payerAddress := common.BytesToAddress(crypto.Keccak256(payer)[12:])
} else {
st.state.AddBalance(st.msg.From(), remaining)
}
// Also return remaining gas to the block gas counter so it is // Also return remaining gas to the block gas counter so it is
// available for the next transaction. // available for the next transaction.

View file

@ -150,6 +150,7 @@ func (m *txSortedMap) Cap(threshold int) types.Transactions {
// Remove deletes a transaction from the maintained map, returning whether the // Remove deletes a transaction from the maintained map, returning whether the
// transaction was found. // transaction was found.
func (m *txSortedMap) Remove(nonce uint64) bool { func (m *txSortedMap) Remove(nonce uint64) bool {
log.Info("I am removing tx list")
// Short circuit if no transaction is present // Short circuit if no transaction is present
_, ok := m.items[nonce] _, ok := m.items[nonce]
if !ok { if !ok {
@ -249,6 +250,8 @@ func (l *txList) Overlaps(tx *types.Transaction) bool {
// If the new transaction is accepted into the list, the lists' cost and gas // If the new transaction is accepted into the list, the lists' cost and gas
// thresholds are also potentially updated. // thresholds are also potentially updated.
func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) { func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) {
log.Info("Trying to add to txList")
// If there's an older better transaction, abort // If there's an older better transaction, abort
old := l.txs.Get(tx.Nonce()) old := l.txs.Get(tx.Nonce())
if old != nil { if old != nil {
@ -268,6 +271,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
if gas := tx.Gas(); l.gascap < gas { if gas := tx.Gas(); l.gascap < gas {
l.gascap = gas l.gascap = gas
} }
log.Info("I am adding it its okay")
return true, old return true, old
} }
@ -296,7 +300,12 @@ func (l *txList) Filter(costLimit *big.Int, gasLimit uint64) (types.Transactions
l.gascap = gasLimit l.gascap = gasLimit
// Filter out all the transactions above the account's funds // Filter out all the transactions above the account's funds
removed := l.txs.Filter(func(tx *types.Transaction) bool { return tx.Cost().Cmp(costLimit) > 0 || tx.Gas() > gasLimit }) removed := l.txs.Filter(func(tx *types.Transaction) bool {
log.Info("Inside filter ","costlimit",costLimit,"txCost",tx.Cost(),"txGas",tx.Gas(),"gasLimit",gasLimit)
return tx.Cost().Cmp(costLimit) > 0 || tx.Gas() > gasLimit
})
log.Info("Removed tx ","tx",removed)
// If the list was strict, filter anything above the lowest nonce // If the list was strict, filter anything above the lowest nonce
var invalids types.Transactions var invalids types.Transactions
@ -323,6 +332,7 @@ func (l *txList) Cap(threshold int) types.Transactions {
// transaction was found, and also returning any transaction invalidated due to // transaction was found, and also returning any transaction invalidated due to
// the deletion (strict mode only). // the deletion (strict mode only).
func (l *txList) Remove(tx *types.Transaction) (bool, types.Transactions) { func (l *txList) Remove(tx *types.Transaction) (bool, types.Transactions) {
log.Info("remove tx list 2")
// Remove the transaction from the set // Remove the transaction from the set
nonce := tx.Nonce() nonce := tx.Nonce()
if removed := l.txs.Remove(nonce); !removed { if removed := l.txs.Remove(nonce); !removed {
@ -495,6 +505,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo
// Discard finds a number of most underpriced transactions, removes them from the // Discard finds a number of most underpriced transactions, removes them from the
// priced list and returns them for further removal from the entire pool. // priced list and returns them for further removal from the entire pool.
func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions { func (l *txPricedList) Discard(count int, local *accountSet) types.Transactions {
log.Info("I am discarding")
drop := make(types.Transactions, 0, count) // Remote underpriced transactions to drop drop := make(types.Transactions, 0, count) // Remote underpriced transactions to drop
save := make(types.Transactions, 0, 64) // Local underpriced transactions to keep save := make(types.Transactions, 0, 64) // Local underpriced transactions to keep

View file

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/common/prque" "github.com/ethereum/go-ethereum/common/prque"
"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/crypto"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
@ -359,6 +360,7 @@ func (pool *TxPool) loop() {
// Any non-locals old enough should be removed // Any non-locals old enough should be removed
if time.Since(pool.beats[addr]) > pool.config.Lifetime { if time.Since(pool.beats[addr]) > pool.config.Lifetime {
for _, tx := range pool.queue[addr].Flatten() { for _, tx := range pool.queue[addr].Flatten() {
log.Info("PILGEEEEE REMOVING TRANSACTION 8")
pool.removeTx(tx.Hash(), true) pool.removeTx(tx.Hash(), true)
} }
} }
@ -415,6 +417,7 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
pool.gasPrice = price pool.gasPrice = price
for _, tx := range pool.priced.Cap(price, pool.locals) { for _, tx := range pool.priced.Cap(price, pool.locals) {
log.Info("Gas price low i removed")
pool.removeTx(tx.Hash(), false) pool.removeTx(tx.Hash(), false)
} }
log.Info("Transaction pool price threshold updated", "price", price) log.Info("Transaction pool price threshold updated", "price", price)
@ -512,11 +515,12 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// Heuristic limit, reject transactions over 32KB to prevent DOS attacks // Heuristic limit, reject transactions over 32KB to prevent DOS attacks
if tx.Payer != nil { if len(tx.Payer()) != 0 {
log.Info("pilge", "payer :", tx.Payer()) log.Info("pilge", "payer :", tx.Payer())
log.Info("pilge", "sender :", tx.Sender()) log.Info("pilge", "sender :", tx.Sender())
log.Info("pilge", "payer signature :", tx.PayerSig()) log.Info("pilge", "payer signature :", tx.PayerSig())
log.Info("pilge", "payer address", common.BytesToAddress(crypto.Keccak256(tx.Payer())[12:]))
// TODO PATU CHECK SIGNATURE FOR PAYER
} }
if tx.Size() > 32*1024 { if tx.Size() > 32*1024 {
@ -546,10 +550,24 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if pool.currentState.GetNonce(from) > tx.Nonce() { if pool.currentState.GetNonce(from) > tx.Nonce() {
return ErrNonceTooLow return ErrNonceTooLow
} }
//if payer exists and stuff here
// Transactor should have enough funds to cover the costs // Transactor should have enough funds to cover the costs
// cost == V + GP * GL // cost == V + GP * GL
if len(tx.Payer()) != 0 {
payerAdress := common.BytesToAddress(crypto.Keccak256(tx.Payer())[12:])
log.Info("pilge", "balance :", pool.currentState.GetBalance(payerAdress))
log.Info("pilge", "cost :", tx.Cost())
log.Info("pilge", "payer :", payerAdress)
if pool.currentState.GetBalance(payerAdress).Cmp(tx.Cost()) < 0 {
return ErrInsufficientFunds
}
} else if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 {
log.Info("pilge", "balance :", pool.currentState.GetBalance(from))
log.Info("pilge", "cost :", tx.Cost())
log.Info("pilge", "from :", from)
if pool.currentState.GetBalance(from).Cmp(tx.Cost()) < 0 {
return ErrInsufficientFunds return ErrInsufficientFunds
} }
// Ensure the transaction has more gas than the basic tx fee. // Ensure the transaction has more gas than the basic tx fee.
@ -560,6 +578,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if tx.Gas() < intrGas { if tx.Gas() < intrGas {
return ErrIntrinsicGas return ErrIntrinsicGas
} }
log.Info("pilge", "VALIDATED", 0)
return nil return nil
} }
@ -597,28 +616,34 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
for _, tx := range drop { for _, tx := range drop {
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice()) log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "price", tx.GasPrice())
underpricedTxMeter.Mark(1) underpricedTxMeter.Mark(1)
log.Info("Discarding freshly underpriced transaction")
pool.removeTx(tx.Hash(), false) pool.removeTx(tx.Hash(), false)
} }
} }
// Try to replace an existing transaction in the pending pool // Try to replace an existing transaction in the pending pool
from, _ := types.Sender(pool.signer, tx) // already validated from, _ := types.Sender(pool.signer, tx) // already validated
if list := pool.pending[from]; list != nil && list.Overlaps(tx) { if list := pool.pending[from]; list != nil && list.Overlaps(tx) {
log.Info("Ben var girememek")
// Nonce already pending, check if required price bump is met // Nonce already pending, check if required price bump is met
inserted, old := list.Add(tx, pool.config.PriceBump) inserted, old := list.Add(tx, pool.config.PriceBump)
if !inserted { if !inserted {
log.Info("PATU!!1")
pendingDiscardMeter.Mark(1) pendingDiscardMeter.Mark(1)
return false, ErrReplaceUnderpriced return false, ErrReplaceUnderpriced
} }
// New transaction is better, replace old one // New transaction is better, replace old one
if old != nil { if old != nil {
log.Info("PATU!!2")
pool.all.Remove(old.Hash()) pool.all.Remove(old.Hash())
pool.priced.Removed(1) pool.priced.Removed(1)
pendingReplaceMeter.Mark(1) pendingReplaceMeter.Mark(1)
} }
log.Info("I am adding tx3")
pool.all.Add(tx) pool.all.Add(tx)
pool.priced.Put(tx) pool.priced.Put(tx)
pool.journalTx(from, tx) pool.journalTx(from, tx)
pool.queueTxEvent(tx) pool.queueTxEvent(tx)
log.Info("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())
log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To()) log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To())
return old != nil, nil return old != nil, nil
} }
@ -638,7 +663,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
localGauge.Inc(1) localGauge.Inc(1)
} }
pool.journalTx(from, tx) pool.journalTx(from, tx)
log.Info("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To())
log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To()) log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To())
return replaced, nil return replaced, nil
} }
@ -660,6 +685,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er
} }
// Discard any previous transaction and mark this // Discard any previous transaction and mark this
if old != nil { if old != nil {
log.Info("Removed 13")
pool.all.Remove(old.Hash()) pool.all.Remove(old.Hash())
pool.priced.Removed(1) pool.priced.Removed(1)
queuedReplaceMeter.Mark(1) queuedReplaceMeter.Mark(1)
@ -668,6 +694,7 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er
queuedGauge.Inc(1) queuedGauge.Inc(1)
} }
if pool.all.Get(hash) == nil { if pool.all.Get(hash) == nil {
log.Info("I am adding tx1")
pool.all.Add(tx) pool.all.Add(tx)
pool.priced.Put(tx) pool.priced.Put(tx)
} }
@ -701,6 +728,8 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
if !inserted { if !inserted {
// An older transaction was better, discard this // An older transaction was better, discard this
pool.all.Remove(hash) pool.all.Remove(hash)
log.Info("Removed 1")
pool.priced.Removed(1) pool.priced.Removed(1)
pendingDiscardMeter.Mark(1) pendingDiscardMeter.Mark(1)
@ -708,6 +737,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
} }
// Otherwise discard any previous transaction and mark this // Otherwise discard any previous transaction and mark this
if old != nil { if old != nil {
log.Info("Removed 12")
pool.all.Remove(old.Hash()) pool.all.Remove(old.Hash())
pool.priced.Removed(1) pool.priced.Removed(1)
@ -718,6 +748,7 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
} }
// Failsafe to work around direct pending inserts (tests) // Failsafe to work around direct pending inserts (tests)
if pool.all.Get(hash) == nil { if pool.all.Get(hash) == nil {
log.Info("I am adding tx2")
pool.all.Add(tx) pool.all.Add(tx)
pool.priced.Put(tx) pool.priced.Put(tx)
} }
@ -864,6 +895,7 @@ func (pool *TxPool) Get(hash common.Hash) *types.Transaction {
// removeTx removes a single transaction from the queue, moving all subsequent // removeTx removes a single transaction from the queue, moving all subsequent
// transactions back to the future queue. // transactions back to the future queue.
func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) { func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
log.Info("Remove Tx")
// Fetch the transaction we wish to delete // Fetch the transaction we wish to delete
tx := pool.all.Get(hash) tx := pool.all.Get(hash)
if tx == nil { if tx == nil {
@ -872,6 +904,8 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
addr, _ := types.Sender(pool.signer, tx) // already validated during insertion addr, _ := types.Sender(pool.signer, tx) // already validated during insertion
// Remove it from the list of known transactions // Remove it from the list of known transactions
log.Info("Removed 2")
pool.all.Remove(hash) pool.all.Remove(hash)
if outofbound { if outofbound {
pool.priced.Removed(1) pool.priced.Removed(1)
@ -913,6 +947,7 @@ func (pool *TxPool) removeTx(hash common.Hash, outofbound bool) {
// requestPromoteExecutables requests a pool reset to the new head block. // requestPromoteExecutables requests a pool reset to the new head block.
// The returned channel is closed when the reset has occurred. // The returned channel is closed when the reset has occurred.
func (pool *TxPool) requestReset(oldHead *types.Header, newHead *types.Header) chan struct{} { func (pool *TxPool) requestReset(oldHead *types.Header, newHead *types.Header) chan struct{} {
log.Info("reset requested")
select { select {
case pool.reqResetCh <- &txpoolResetRequest{oldHead, newHead}: case pool.reqResetCh <- &txpoolResetRequest{oldHead, newHead}:
return <-pool.reorgDoneCh return <-pool.reorgDoneCh
@ -1077,6 +1112,7 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt
// reset retrieves the current state of the blockchain and ensures the content // reset retrieves the current state of the blockchain and ensures the content
// of the transaction pool is valid with regard to the chain state. // of the transaction pool is valid with regard to the chain state.
func (pool *TxPool) reset(oldHead, newHead *types.Header) { func (pool *TxPool) reset(oldHead, newHead *types.Header) {
log.Info("tx pool resetted")
// If we're reorging an old state, reinject all dropped transactions // If we're reorging an old state, reinject all dropped transactions
var reinject types.Transactions var reinject types.Transactions
@ -1180,16 +1216,21 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _, tx := range forwards { for _, tx := range forwards {
hash := tx.Hash() hash := tx.Hash()
pool.all.Remove(hash) pool.all.Remove(hash)
log.Info("PILGEEEEE REMOVING TRANSACTION 2")
log.Trace("Removed old queued transaction", "hash", hash) log.Trace("Removed old queued transaction", "hash", hash)
} }
// Drop all transactions that are too costly (low balance or out of gas) // Drop all transactions that are too costly (low balance or out of gas)
drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas) //drops, _ := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops { // drops:=[]
hash := tx.Hash() // for _, tx := range drops {
pool.all.Remove(hash) // // TODO Fix
log.Trace("Removed unpayable queued transaction", "hash", hash) // hash := tx.Hash()
} // pool.all.Remove(hash)
queuedNofundsMeter.Mark(int64(len(drops))) // log.Info("PILGEEEEE REMOVING TRANSACTION")
// log.Trace("Removed unpayable queued transaction", "hash", hash)
// }
// queuedNofundsMeter.Mark(int64(len(drops)))
// Gather all executable transactions and promote them // Gather all executable transactions and promote them
readies := list.Ready(pool.pendingNonces.get(addr)) readies := list.Ready(pool.pendingNonces.get(addr))
@ -1209,16 +1250,17 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Trans
for _, tx := range caps { for _, tx := range caps {
hash := tx.Hash() hash := tx.Hash()
pool.all.Remove(hash) pool.all.Remove(hash)
log.Info("PILGEEEEE REMOVING TRANSACTION 3")
log.Trace("Removed cap-exceeding queued transaction", "hash", hash) log.Trace("Removed cap-exceeding queued transaction", "hash", hash)
} }
queuedRateLimitMeter.Mark(int64(len(caps))) queuedRateLimitMeter.Mark(int64(len(caps)))
} }
// Mark all the items dropped as removed // Mark all the items dropped as removed
pool.priced.Removed(len(forwards) + len(drops) + len(caps)) // pool.priced.Removed(len(forwards) + len(drops) + len(caps))
queuedGauge.Dec(int64(len(forwards) + len(drops) + len(caps))) // queuedGauge.Dec(int64(len(forwards) + len(drops) + len(caps)))
if pool.locals.contains(addr) { // if pool.locals.contains(addr) {
localGauge.Dec(int64(len(forwards) + len(drops) + len(caps))) // localGauge.Dec(int64(len(forwards) + len(drops) + len(caps)))
} // }
// Delete the entire queue entry if it became empty. // Delete the entire queue entry if it became empty.
if list.Empty() { if list.Empty() {
delete(pool.queue, addr) delete(pool.queue, addr)
@ -1270,7 +1312,7 @@ func (pool *TxPool) truncatePending() {
// Drop the transaction from the global pools too // Drop the transaction from the global pools too
hash := tx.Hash() hash := tx.Hash()
pool.all.Remove(hash) pool.all.Remove(hash)
log.Info("PILGEEEEE REMOVING TRANSACTION 4")
// Update the account nonce to the dropped transaction // Update the account nonce to the dropped transaction
pool.pendingNonces.setIfLower(offenders[i], tx.Nonce()) pool.pendingNonces.setIfLower(offenders[i], tx.Nonce())
log.Trace("Removed fairness-exceeding pending transaction", "hash", hash) log.Trace("Removed fairness-exceeding pending transaction", "hash", hash)
@ -1297,7 +1339,7 @@ func (pool *TxPool) truncatePending() {
// Drop the transaction from the global pools too // Drop the transaction from the global pools too
hash := tx.Hash() hash := tx.Hash()
pool.all.Remove(hash) pool.all.Remove(hash)
log.Info("PILGEEEEE REMOVING TRANSACTION5 ")
// Update the account nonce to the dropped transaction // Update the account nonce to the dropped transaction
pool.pendingNonces.setIfLower(addr, tx.Nonce()) pool.pendingNonces.setIfLower(addr, tx.Nonce())
log.Trace("Removed fairness-exceeding pending transaction", "hash", hash) log.Trace("Removed fairness-exceeding pending transaction", "hash", hash)
@ -1343,6 +1385,7 @@ func (pool *TxPool) truncateQueue() {
// Drop all transactions if they are less than the overflow // Drop all transactions if they are less than the overflow
if size := uint64(list.Len()); size <= drop { if size := uint64(list.Len()); size <= drop {
for _, tx := range list.Flatten() { for _, tx := range list.Flatten() {
log.Info("PILGEEEEE REMOVING TRANSACTION 7")
pool.removeTx(tx.Hash(), true) pool.removeTx(tx.Hash(), true)
} }
drop -= size drop -= size
@ -1352,6 +1395,7 @@ func (pool *TxPool) truncateQueue() {
// Otherwise drop only last few transactions // Otherwise drop only last few transactions
txs := list.Flatten() txs := list.Flatten()
for i := len(txs) - 1; i >= 0 && drop > 0; i-- { for i := len(txs) - 1; i >= 0 && drop > 0; i-- {
log.Info("PILGEEEEE REMOVING TRANSACTION 6")
pool.removeTx(txs[i].Hash(), true) pool.removeTx(txs[i].Hash(), true)
drop-- drop--
queuedRateLimitMeter.Mark(1) queuedRateLimitMeter.Mark(1)
@ -1372,27 +1416,34 @@ func (pool *TxPool) demoteUnexecutables() {
for _, tx := range olds { for _, tx := range olds {
hash := tx.Hash() hash := tx.Hash()
pool.all.Remove(hash) pool.all.Remove(hash)
log.Info("Removed unpayable pending transaction")
log.Trace("Removed old pending transaction", "hash", hash) log.Trace("Removed old pending transaction", "hash", hash)
} }
// Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later // Drop all transactions that are too costly (low balance or out of gas), and queue any invalids back for later
drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas) // drops, invalids := list.Filter(pool.currentState.GetBalance(addr), pool.currentMaxGas)
for _, tx := range drops { // drops:=[]
hash := tx.Hash() // invalids:=[]
log.Trace("Removed unpayable pending transaction", "hash", hash) // TODO PATU
pool.all.Remove(hash) // for _, tx := range drops {
} // hash := tx.Hash()
pool.priced.Removed(len(olds) + len(drops)) // log.Trace("Removed unpayable pending transaction", "hash", hash)
pendingNofundsMeter.Mark(int64(len(drops))) // log.Info("Removed unpayable pending transaction")
// pool.all.Remove(hash)
// }
// pool.priced.Removed(len(olds) + len(drops))
// pendingNofundsMeter.Mark(int64(len(drops)))
for _, tx := range invalids { // for _, tx := range invalids {
hash := tx.Hash() // log.Info("Invalid txs")
log.Trace("Demoting pending transaction", "hash", hash) // hash := tx.Hash()
pool.enqueueTx(hash, tx) // log.Trace("Demoting pending transaction", "hash", hash)
} // pool.enqueueTx(hash, tx)
pendingGauge.Dec(int64(len(olds) + len(drops) + len(invalids))) // }
if pool.locals.contains(addr) { // pendingGauge.Dec(int64(len(olds) + len(drops) + len(invalids)))
localGauge.Dec(int64(len(olds) + len(drops) + len(invalids))) // if pool.locals.contains(addr) {
} // localGauge.Dec(int64(len(olds) + len(drops) + len(invalids)))
// }
// If there's a gap in front, alert (should never happen) and postpone all transactions // If there's a gap in front, alert (should never happen) and postpone all transactions
if list.Len() > 0 && list.txs.Get(nonce) == nil { if list.Len() > 0 && list.txs.Get(nonce) == nil {
gapped := list.Cap(0) gapped := list.Cap(0)
@ -1552,6 +1603,7 @@ func (t *txLookup) Add(tx *types.Transaction) {
// Remove removes a transaction from the lookup. // Remove removes a transaction from the lookup.
func (t *txLookup) Remove(hash common.Hash) { func (t *txLookup) Remove(hash common.Hash) {
log.Info("Removing tx")
t.lock.Lock() t.lock.Lock()
defer t.lock.Unlock() defer t.lock.Unlock()

View file

@ -234,6 +234,7 @@ func (tx *Transaction) AsMessage(s Signer) (Message, error) {
amount: tx.data.Amount, amount: tx.data.Amount,
data: tx.data.Payload, data: tx.data.Payload,
checkNonce: true, checkNonce: true,
payer: tx.data.Payer,
} }
var err error var err error
@ -402,9 +403,11 @@ type Message struct {
gasPrice *big.Int gasPrice *big.Int
data []byte data []byte
checkNonce bool checkNonce bool
payer []byte
} }
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool) Message { func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool,payer []byte) Message {
return Message{ return Message{
from: from, from: from,
to: to, to: to,
@ -414,6 +417,7 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
gasPrice: gasPrice, gasPrice: gasPrice,
data: data, data: data,
checkNonce: checkNonce, checkNonce: checkNonce,
payer: payer,
} }
} }
@ -425,3 +429,4 @@ func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce } func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data } func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce } func (m Message) CheckNonce() bool { return m.checkNonce }
func (m Message) Payer() []byte { return common.CopyBytes(m.payer) }

View file

@ -186,7 +186,7 @@ func (evm *EVM) Interpreter() Interpreter {
// parameters. It also handles any necessary value transfer required and takes // parameters. It also handles any necessary value transfer required and takes
// the necessary steps to create accounts and reverses the state in case of an // the necessary steps to create accounts and reverses the state in case of an
// execution error or failed value transfer. // execution error or failed value transfer.
func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error) { func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas uint64, value *big.Int, payer common.Address) (ret []byte, leftOverGas uint64, err error) {
if evm.vmConfig.NoRecursion && evm.depth > 0 { if evm.vmConfig.NoRecursion && evm.depth > 0 {
return nil, gas, nil return nil, gas, nil
} }
@ -196,7 +196,11 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
return nil, gas, ErrDepth return nil, gas, ErrDepth
} }
// Fail if we're trying to transfer more than the available balance // Fail if we're trying to transfer more than the available balance
if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) { if (payer != [20]byte{} ){
if !evm.Context.CanTransfer(evm.StateDB, payer, value) {
return nil, gas, ErrInsufficientBalance
}
} else if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) {
return nil, gas, ErrInsufficientBalance return nil, gas, ErrInsufficientBalance
} }
@ -222,7 +226,12 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
} }
evm.StateDB.CreateAccount(addr) evm.StateDB.CreateAccount(addr)
} }
evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) if (payer != [20]byte{} ){
log.Info("Transferin from payer")
evm.Transfer(evm.StateDB, payer, to.Address(), value)
}else {
evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value)
}
// Initialise a new contract and set the code that is to be used by the EVM. // Initialise a new contract and set the code that is to be used by the EVM.
// The contract is a scoped environment for this execution context only. // The contract is a scoped environment for this execution context only.
contract := NewContract(caller, to, value, gas) contract := NewContract(caller, to, value, gas)

View file

@ -760,7 +760,7 @@ func opCall(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
if value.Sign() != 0 { if value.Sign() != 0 {
gas += params.CallStipend gas += params.CallStipend
} }
ret, returnGas, err := interpreter.evm.Call(contract, toAddr, args, gas, value) ret, returnGas, err := interpreter.evm.Call(contract, toAddr, args, gas, value, [20]byte{})
if err != nil { if err != nil {
stack.push(interpreter.intPool.getZero()) stack.push(interpreter.intPool.getZero())
} else { } else {

View file

@ -116,6 +116,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
input, input,
cfg.GasLimit, cfg.GasLimit,
cfg.Value, cfg.Value,
[20]byte{},
) )
return ret, cfg.State, err return ret, cfg.State, err
@ -164,6 +165,7 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
input, input,
cfg.GasLimit, cfg.GasLimit,
cfg.Value, cfg.Value,
[20]byte{},
) )
return ret, leftOverGas, err return ret, leftOverGas, err

View file

@ -442,6 +442,8 @@ func (api *PrivateDebugAPI) StandardTraceBadBlockToFile(ctx context.Context, has
// executes all the transactions contained within. The return value will be one item // executes all the transactions contained within. The return value will be one item
// per transaction, dependent on the requestd tracer. // per transaction, dependent on the requestd tracer.
func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block, config *TraceConfig) ([]*txTraceResult, error) { func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block, config *TraceConfig) ([]*txTraceResult, error) {
log.Info("traceBlock")
// Create the parent state database // Create the parent state database
if err := api.eth.engine.VerifyHeader(api.eth.blockchain, block.Header(), true); err != nil { if err := api.eth.engine.VerifyHeader(api.eth.blockchain, block.Header(), true); err != nil {
return nil, err return nil, err
@ -525,6 +527,8 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
// be one filename per transaction traced. // be one filename per transaction traced.
func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) { func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block *types.Block, config *StdTraceConfig) ([]string, error) {
// If we're tracing a single transaction, make sure it's present // If we're tracing a single transaction, make sure it's present
log.Info("standardTraceBlockToFile")
if config != nil && config.TxHash != (common.Hash{}) { if config != nil && config.TxHash != (common.Hash{}) {
if !containsTx(block, config.TxHash) { if !containsTx(block, config.TxHash) {
return nil, fmt.Errorf("transaction %#x not found in block", config.TxHash) return nil, fmt.Errorf("transaction %#x not found in block", config.TxHash)
@ -724,6 +728,8 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha
// be tracer dependent. // be tracer dependent.
func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, vmctx vm.Context, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, vmctx vm.Context, statedb *state.StateDB, config *TraceConfig) (interface{}, error) {
// Assemble the structured logger or the JavaScript tracer // Assemble the structured logger or the JavaScript tracer
log.Info("traceTx")
var ( var (
tracer vm.Tracer tracer vm.Tracer
err error err error
@ -783,6 +789,8 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
// computeTxEnv returns the execution environment of a certain transaction. // computeTxEnv returns the execution environment of a certain transaction.
func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) { func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, reexec uint64) (core.Message, vm.Context, *state.StateDB, error) {
// Create the parent state database // Create the parent state database
log.Info("computeTxEnv")
block := api.eth.blockchain.GetBlockByHash(blockHash) block := api.eth.blockchain.GetBlockByHash(blockHash)
if block == nil { if block == nil {
return nil, vm.Context{}, nil, fmt.Errorf("block %#x not found", blockHash) return nil, vm.Context{}, nil, fmt.Errorf("block %#x not found", blockHash)

View file

@ -118,7 +118,8 @@ type CallMsg struct {
Gas uint64 // if 0, the call executes with near-infinite gas Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation Data []byte
Payer []byte // input data, usually an ABI-encoded contract method invocation
} }
// A ContractCaller provides contract calls, essentially transactions that are executed by // A ContractCaller provides contract calls, essentially transactions that are executed by

View file

@ -741,6 +741,7 @@ type CallArgs struct {
GasPrice *hexutil.Big `json:"gasPrice"` GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"` Value *hexutil.Big `json:"value"`
Data *hexutil.Bytes `json:"data"` Data *hexutil.Bytes `json:"data"`
Payer []byte `json:"payer"`
} }
// account indicates the overriding fields of account during the execution of // account indicates the overriding fields of account during the execution of
@ -761,6 +762,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now()) defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
log.Info("DoCall")
if state == nil || err != nil { if state == nil || err != nil {
return nil, 0, false, err return nil, 0, false, err
} }
@ -828,7 +830,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
} }
// Create new call message // Create new call message
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false) msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false,args.Payer)
// Setup context so it may be cancelled the call has completed // Setup context so it may be cancelled the call has completed
// or, in case of unmetered gas, setup a context with a timeout. // or, in case of unmetered gas, setup a context with a timeout.

View file

@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/log"
) )
type LesApiBackend struct { type LesApiBackend struct {
@ -178,6 +179,8 @@ func (b *LesApiBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
} }
func (b *LesApiBackend) RemoveTx(txHash common.Hash) { func (b *LesApiBackend) RemoveTx(txHash common.Hash) {
log.Info("api backend removing tx")
b.eth.txPool.RemoveTx(txHash) b.eth.txPool.RemoveTx(txHash)
} }

View file

@ -128,7 +128,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
from := statedb.GetOrNewStateObject(bankAddr) from := statedb.GetOrNewStateObject(bankAddr)
from.SetBalance(math.MaxBig256) from.SetBalance(math.MaxBig256)
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)} msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false,nil)}
context := core.NewEVMContext(msg, header, bc, nil) context := core.NewEVMContext(msg, header, bc, nil)
vmenv := vm.NewEVM(context, statedb, config, vm.Config{}) vmenv := vm.NewEVM(context, statedb, config, vm.Config{})
@ -142,7 +142,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
header := lc.GetHeaderByHash(bhash) header := lc.GetHeaderByHash(bhash)
state := light.NewState(ctx, header, lc.Odr()) state := light.NewState(ctx, header, lc.Odr())
state.SetBalance(bankAddr, math.MaxBig256) state.SetBalance(bankAddr, math.MaxBig256)
msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)} msg := callmsg{types.NewMessage(bankAddr, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false,nil)}
context := core.NewEVMContext(msg, header, lc, nil) context := core.NewEVMContext(msg, header, lc, nil)
vmenv := vm.NewEVM(context, state, config, vm.Config{}) vmenv := vm.NewEVM(context, state, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64) gp := new(core.GasPool).AddGas(math.MaxUint64)

View file

@ -194,7 +194,7 @@ func odrContractCall(ctx context.Context, db ethdb.Database, bc *core.BlockChain
// Perform read-only call. // Perform read-only call.
st.SetBalance(testBankAddress, math.MaxBig256) st.SetBalance(testBankAddress, math.MaxBig256)
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false)} msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 1000000, new(big.Int), data, false,nil)}
context := core.NewEVMContext(msg, header, chain, nil) context := core.NewEVMContext(msg, header, chain, nil)
vmenv := vm.NewEVM(context, st, config, vm.Config{}) vmenv := vm.NewEVM(context, st, config, vm.Config{})
gp := new(core.GasPool).AddGas(math.MaxUint64) gp := new(core.GasPool).AddGas(math.MaxUint64)

View file

@ -507,6 +507,8 @@ func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common
// RemoveTransactions removes all given transactions from the pool. // RemoveTransactions removes all given transactions from the pool.
func (pool *TxPool) RemoveTransactions(txs types.Transactions) { func (pool *TxPool) RemoveTransactions(txs types.Transactions) {
log.Info("Removing Tx light 2")
pool.mu.Lock() pool.mu.Lock()
defer pool.mu.Unlock() defer pool.mu.Unlock()
@ -524,6 +526,8 @@ func (pool *TxPool) RemoveTransactions(txs types.Transactions) {
// RemoveTx removes the transaction with the given hash from the pool. // RemoveTx removes the transaction with the given hash from the pool.
func (pool *TxPool) RemoveTx(hash common.Hash) { func (pool *TxPool) RemoveTx(hash common.Hash) {
log.Info("Removing tx light")
pool.mu.Lock() pool.mu.Lock()
defer pool.mu.Unlock() defer pool.mu.Unlock()
// delete from pending pool // delete from pending pool

View file

@ -452,6 +452,7 @@ func (w *worker) mainLoop() {
// Note all transactions received may not be continuous with transactions // Note all transactions received may not be continuous with transactions
// already included in the current mining block. These transactions will // already included in the current mining block. These transactions will
// be automatically eliminated. // be automatically eliminated.
log.Info("Tx arrived to main loop")
if !w.isRunning() && w.current != nil { if !w.isRunning() && w.current != nil {
// If block is already full, abort // If block is already full, abort
if gp := w.current.gasPool; gp != nil && gp.Gas() < params.TxGas { if gp := w.current.gasPool; gp != nil && gp.Gas() < params.TxGas {
@ -462,12 +463,16 @@ func (w *worker) mainLoop() {
w.mu.RUnlock() w.mu.RUnlock()
txs := make(map[common.Address]types.Transactions) txs := make(map[common.Address]types.Transactions)
log.Info("Pooled new future transaction", "txs", txs)
for _, tx := range ev.Txs { for _, tx := range ev.Txs {
acc, _ := types.Sender(w.current.signer, tx) acc, _ := types.Sender(w.current.signer, tx)
txs[acc] = append(txs[acc], tx) txs[acc] = append(txs[acc], tx)
} }
txset := types.NewTransactionsByPriceAndNonce(w.current.signer, txs) txset := types.NewTransactionsByPriceAndNonce(w.current.signer, txs)
tcount := w.current.tcount tcount := w.current.tcount
log.Info("mainLoop")
w.commitTransactions(txset, coinbase, nil) w.commitTransactions(txset, coinbase, nil)
// Only update the snapshot if any new transactons were added // Only update the snapshot if any new transactons were added
// to the pending block // to the pending block
@ -702,6 +707,8 @@ func (w *worker) updateSnapshot() {
} }
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) { func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
log.Info("commitTransaction")
snap := w.current.state.Snapshot() snap := w.current.state.Snapshot()
receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig()) receipt, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
@ -716,6 +723,8 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
} }
func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coinbase common.Address, interrupt *int32) bool { func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coinbase common.Address, interrupt *int32) bool {
log.Info("commitTransactionssssss")
// Short circuit if current is nil // Short circuit if current is nil
if w.current == nil { if w.current == nil {
return true return true
@ -773,6 +782,7 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
} }
// Start executing the transaction // Start executing the transaction
w.current.state.Prepare(tx.Hash(), common.Hash{}, w.current.tcount) w.current.state.Prepare(tx.Hash(), common.Hash{}, w.current.tcount)
log.Info("mineBlock")
logs, err := w.commitTransaction(tx, coinbase) logs, err := w.commitTransaction(tx, coinbase)
switch err { switch err {
@ -923,6 +933,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
// Fill the block with all available pending transactions. // Fill the block with all available pending transactions.
pending, err := w.eth.TxPool().Pending() pending, err := w.eth.TxPool().Pending()
log.Info("Pending tx", "tx", pending)
if err != nil { if err != nil {
log.Error("Failed to fetch pending transactions", "err", err) log.Error("Failed to fetch pending transactions", "err", err)
return return
@ -942,12 +953,15 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
} }
if len(localTxs) > 0 { if len(localTxs) > 0 {
txs := types.NewTransactionsByPriceAndNonce(w.current.signer, localTxs) txs := types.NewTransactionsByPriceAndNonce(w.current.signer, localTxs)
log.Info("commitNewWork")
if w.commitTransactions(txs, w.coinbase, interrupt) { if w.commitTransactions(txs, w.coinbase, interrupt) {
return return
} }
} }
if len(remoteTxs) > 0 { if len(remoteTxs) > 0 {
txs := types.NewTransactionsByPriceAndNonce(w.current.signer, remoteTxs) txs := types.NewTransactionsByPriceAndNonce(w.current.signer, remoteTxs)
log.Info("commitNewWork Remote")
if w.commitTransactions(txs, w.coinbase, interrupt) { if w.commitTransactions(txs, w.coinbase, interrupt) {
return return
} }

View file

@ -23,7 +23,6 @@ import (
"math/big" "math/big"
"strconv" "strconv"
"strings" "strings"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/common/math"
@ -36,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/log"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
) )
@ -164,6 +164,8 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
// RunNoVerify runs a specific subtest and returns the statedb and post-state root // RunNoVerify runs a specific subtest and returns the statedb and post-state root
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, common.Hash, error) { func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config) (*state.StateDB, common.Hash, error) {
log.Info("RunNoVerify")
config, eips, err := getVMConfig(subtest.Fork) config, eips, err := getVMConfig(subtest.Fork)
if err != nil { if err != nil {
return nil, common.Hash{}, UnsupportedForkError{subtest.Fork} return nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
@ -279,7 +281,7 @@ func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
return nil, fmt.Errorf("invalid tx data %q", dataHex) return nil, fmt.Errorf("invalid tx data %q", dataHex)
} }
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true) msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, true, nil)
return msg, nil return msg, nil
} }

View file

@ -117,7 +117,7 @@ func (t *VMTest) Run(vmconfig vm.Config) error {
func (t *VMTest) exec(statedb *state.StateDB, vmconfig vm.Config) ([]byte, uint64, error) { func (t *VMTest) exec(statedb *state.StateDB, vmconfig vm.Config) ([]byte, uint64, error) {
evm := t.newEVM(statedb, vmconfig) evm := t.newEVM(statedb, vmconfig)
e := t.json.Exec e := t.json.Exec
return evm.Call(vm.AccountRef(e.Caller), e.Address, e.Data, e.GasLimit, e.Value) return evm.Call(vm.AccountRef(e.Caller), e.Address, e.Data, e.GasLimit, e.Value,[20]byte{})
} }
func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM { func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM {