fix signature issue for homestead; add balance in destination shard in propose stage

pull/1368/head
chao 5 years ago committed by Chao Ma
parent 38a13e1010
commit d293e406cc
  1. 9
      core/state_processor.go
  2. 1
      core/state_transition.go
  3. 15
      core/types/transaction_signing.go
  4. 21
      node/node_newblock.go
  5. 4
      node/worker/worker.go

@ -67,6 +67,11 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.DB, cfg vm.C
allLogs []*types.Log
gp = new(GasPool).AddGas(block.GasLimit())
)
for _, cx := range block.IncomingReceipts() {
ApplyIncomingReceipt(statedb, cx)
}
// Iterate over and process the individual transactions
for i, tx := range block.Transactions() {
statedb.Prepare(tx.Hash(), block.Hash(), i)
@ -81,10 +86,6 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.DB, cfg vm.C
allLogs = append(allLogs, receipt.Logs...)
}
for _, cx := range block.IncomingReceipts() {
ApplyIncomingReceipt(statedb, cx)
}
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
_, err := p.engine.Finalize(p.bc, header, statedb, block.Transactions(), receipts, outcxs, incxs)
if err != nil {

@ -143,7 +143,6 @@ func ApplyIncomingReceipt(db *state.DB, cxp *types.CXReceiptsProof) {
// TODO: how to charge gas here?
for _, cx := range cxp.Receipts {
utils.GetLogInstance().Debug("hehe add incoming receipts")
if cx == nil || cx.To == nil { // should not happend
utils.Logger().Warn().Msg("ApplyIncomingReceipts: Invalid incoming receipt!!")
continue

@ -42,15 +42,7 @@ type sigCache struct {
// MakeSigner returns a Signer based on the given chain config and block number.
func MakeSigner(config *params.ChainConfig, blockNumber *big.Int) Signer {
var signer Signer
switch {
// TODO (chao) clean up different forks in ETH code
case config.IsEIP155(blockNumber):
signer = NewEIP155Signer(config.ChainID)
case config.IsHomestead(blockNumber):
signer = HomesteadSigner{}
default:
signer = FrontierSigner{}
}
signer = NewEIP155Signer(config.ChainID)
return signer
}
@ -233,13 +225,12 @@ func (fs FrontierSigner) Sender(tx *Transaction) (common.Address, error) {
func recoverPlain(sighash common.Hash, R, S, Vb *big.Int, homestead bool) (common.Address, error) {
V := byte(Vb.Uint64() - 27)
fmt.Println("ops0", "R", R, "S", S, "V", V)
if Vb.BitLen() > 8 {
fmt.Println("ops1", "R", R, "S", S, "V", V)
fmt.Println("ops1", "R", R, "S", S, "V", V, "IsHomestead", homestead)
return common.Address{}, ErrInvalidSig
}
if !crypto.ValidateSignatureValues(V, R, S, homestead) {
fmt.Println("ops2", "R", R, "S", S, "V", V)
fmt.Println("ops2", "R", R, "S", S, "V", V, "IsHomestead", homestead)
return common.Address{}, ErrInvalidSig
}
// encode the signature in uncompressed format

@ -64,6 +64,17 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
Uint64("blockNum", node.Blockchain().CurrentBlock().NumberU64()+1).
Int("selectedTxs", len(selectedTxs)).
Msg("PROPOSING NEW BLOCK ------------------------------------------------")
// Propose cross shard receipts
receiptsList := node.proposeReceiptsProof()
if len(receiptsList) != 0 {
if err := node.Worker.CommitReceipts(receiptsList, coinbase); err != nil {
ctxerror.Log15(utils.GetLogger().Error,
ctxerror.New("cannot commit receipts").
WithCause(err))
}
}
if err := node.Worker.CommitTransactions(selectedTxs, coinbase); err != nil {
ctxerror.Log15(utils.GetLogger().Error,
ctxerror.New("cannot commit transactions").
@ -88,16 +99,6 @@ func (node *Node) WaitForConsensusReadyv2(readySignal chan struct{}, stopChan ch
}
}
// Propose cross shard receipts
receiptsList := node.proposeReceiptsProof()
if len(receiptsList) != 0 {
if err := node.Worker.CommitReceipts(receiptsList, coinbase); err != nil {
ctxerror.Log15(utils.GetLogger().Error,
ctxerror.New("cannot commit receipts").
WithCause(err))
}
}
if node.NodeConfig.ShardID == 0 {
crossLinksToPropose, err := node.ProposeCrossLinkDataForBeaconchain()
if err == nil {

@ -124,6 +124,10 @@ func (w *Worker) CommitReceipts(receiptsList []*types.CXReceiptsProof, coinbase
w.current.header.IncomingReceiptHash = types.DeriveSha(types.CXReceiptsProofs(receiptsList))
}
for _, cx := range receiptsList {
core.ApplyIncomingReceipt(w.current.state, cx)
}
for _, cx := range receiptsList {
w.current.incxs = append(w.current.incxs, cx)
}

Loading…
Cancel
Save