Updated Core

This commit is contained in:
AnilChinchawale 2019-01-17 04:38:43 +05:30
parent ffd60b3685
commit fd51ea9fc1
3 changed files with 9 additions and 59 deletions

View file

@ -33,7 +33,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/hashicorp/golang-lru"
"github.com/ethereum/go-ethereum/core/state"
)
const (
@ -204,7 +203,7 @@ func (hc *HeaderChain) WriteHeader(header *types.Header) (status WriteStatus, er
// header writes should be protected by the parent chain mutex individually.
type WhCallback func(*types.Header) error
func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, state *state.StateDB, checkFreq int) (int, error) {
func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
// Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(chain); i++ {
if chain[i].Number.Uint64() != chain[i-1].Number.Uint64()+1 || chain[i].ParentHash != chain[i-1].Hash() {
@ -228,7 +227,7 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, state *state.S
}
seals[len(seals)-1] = true // Last should always be verified to avoid junk
abort, results := hc.engine.VerifyHeaders(hc, state, chain, seals)
abort, results := hc.engine.VerifyHeaders(hc, chain, seals)
defer close(abort)
// Iterate over the headers and ensure they all check out
@ -455,4 +454,4 @@ func (hc *HeaderChain) Engine() consensus.Engine { return hc.engine }
// a header chain does not have blocks available for retrieval.
func (hc *HeaderChain) GetBlock(hash common.Hash, number uint64) *types.Block {
return nil
}
}

View file

@ -73,9 +73,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyDAOHardFork(statedb)
}
if p.config.IsTIPEVMSigner(header.Number) {
statedb.DeleteAddress(common.HexToAddress(common.BlockSigners))
}
InitSignerInTransactions(p.config, header, block.Transactions())
for i, tx := range block.Transactions() {
statedb.Prepare(tx.Hash(), block.Hash(), i)
@ -104,9 +101,6 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
if p.config.DAOForkSupport && p.config.DAOForkBlock != nil && p.config.DAOForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyDAOHardFork(statedb)
}
if p.config.IsTIPEVMSigner(header.Number) {
statedb.DeleteAddress(common.HexToAddress(common.BlockSigners))
}
if cBlock.stop {
return nil, nil, 0, ErrStopPreparingBlock
}
@ -138,9 +132,6 @@ func (p *StateProcessor) ProcessBlockNoValidator(cBlock *CalculatedBlock, stated
// for the transaction, gas used and an error if the transaction failed,
// indicating the block was invalid.
func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, uint64, error) {
if tx.To() != nil && tx.To().String() == common.BlockSigners && config.IsTIPEVMSigner(header.Number) {
return ApplySignTransaction(config, statedb, header, tx, usedGas)
}
msg, err := tx.AsMessage(types.MakeSigner(config, header.Number))
if err != nil {
return nil, 0, err
@ -180,41 +171,6 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, author *common
return receipt, gas, err
}
func ApplySignTransaction(config *params.ChainConfig, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64) (*types.Receipt, uint64, error) {
// Update the state with pending changes
var root []byte
if config.IsByzantium(header.Number) {
statedb.Finalise(true)
} else {
root = statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes()
}
from, err := types.Sender(types.MakeSigner(config, header.Number), tx)
if err != nil {
return nil, 0, err
}
nonce := statedb.GetNonce(from)
if nonce < tx.Nonce() {
return nil, 0, ErrNonceTooHigh
} else if nonce > tx.Nonce() {
return nil, 0, ErrNonceTooLow
}
statedb.SetNonce(from, nonce+1)
// Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
// based on the eip phase, we're passing wether the root touch-delete accounts.
receipt := types.NewReceipt(root, false, *usedGas)
receipt.TxHash = tx.Hash()
receipt.GasUsed = 0
// if the transaction created a contract, store the creation address in the receipt.
// Set the receipt logs and create a bloom for filtering
log := &types.Log{}
log.Address = common.HexToAddress(common.BlockSigners)
log.BlockNumber = header.Number.Uint64()
statedb.AddLog(log)
receipt.Logs = statedb.GetLogs(tx.Hash())
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
return receipt, 0, nil
}
func InitSignerInTransactions(config *params.ChainConfig, header *types.Header, txs types.Transactions) {
nWorker := runtime.NumCPU()
signer := types.MakeSigner(config, header.Number)
@ -239,4 +195,4 @@ func InitSignerInTransactions(config *params.ChainConfig, header *types.Header,
}(from, to)
}
wg.Wait()
}
}

View file

@ -33,8 +33,10 @@ var (
/*
The State Transitioning Model
A state transition is a change made when a transaction is applied to the current world state
The state transitioning model does all all the necessary work to work out a valid new state root.
1) Nonce handling
2) Pre pay gas
3) Create a new state object if the recipient is \0*32
@ -227,22 +229,15 @@ func (st *StateTransition) TransitionDb() (ret []byte, usedGas uint64, failed bo
// error.
vmerr error
)
// for debugging purpose
// TODO: clean it after fixing the issue https://github.com/XDCchain/XDCchain/issues/401
var contractAction string
nonce := uint64(1)
if contractCreation {
ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
contractAction = "contract creation"
} else {
// Increment the nonce for the next transaction
nonce = st.state.GetNonce(sender.Address()) + 1
st.state.SetNonce(sender.Address(), nonce)
st.state.SetNonce(sender.Address(), st.state.GetNonce(sender.Address())+1)
ret, st.gas, vmerr = evm.Call(sender, st.to().Address(), st.data, st.gas, st.value)
contractAction = "contract call"
}
if vmerr != nil {
log.Debug("VM returned with error", "action", contractAction, "contract address", st.to().Address(), "gas", st.gas, "gasPrice", st.gasPrice, "nonce", nonce, "err", vmerr)
log.Debug("VM returned with error", "err", vmerr)
// The only possible consensus-error would be if there wasn't
// sufficient balance to make the transfer happen. The first
// balance transfer may never fail.
@ -278,4 +273,4 @@ func (st *StateTransition) refundGas() {
// gasUsed returns the amount of gas used up by the state transition.
func (st *StateTransition) gasUsed() uint64 {
return st.initialGas - st.gas
}
}