mirror of https://github.com/status-im/op-geth.git
Fixed tx sha creation
This commit is contained in:
parent
9f00aeae29
commit
5d2669dbd3
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/ethereum/eth-go/ethtrie"
|
"github.com/ethereum/eth-go/ethtrie"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strconv"
|
_ "strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -252,20 +252,43 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
|
||||||
func (block *Block) setTransactions(txs []*Transaction) {
|
func (block *Block) setTransactions(txs []*Transaction) {
|
||||||
block.transactions = txs
|
block.transactions = txs
|
||||||
|
|
||||||
|
/*
|
||||||
|
trie := ethtrie.NewTrie(ethutil.Config.Db, "")
|
||||||
|
for i, tx := range txs {
|
||||||
|
trie.Update(strconv.Itoa(i), string(tx.RlpEncode()))
|
||||||
|
}
|
||||||
|
|
||||||
|
switch trie.Root.(type) {
|
||||||
|
case string:
|
||||||
|
block.TxSha = []byte(trie.Root.(string))
|
||||||
|
case []byte:
|
||||||
|
block.TxSha = trie.Root.([]byte)
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("invalid root type %T", trie.Root))
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateTxSha(receipts Receipts) (sha []byte) {
|
||||||
trie := ethtrie.NewTrie(ethutil.Config.Db, "")
|
trie := ethtrie.NewTrie(ethutil.Config.Db, "")
|
||||||
for i, tx := range txs {
|
for i, receipt := range receipts {
|
||||||
trie.Update(strconv.Itoa(i), string(tx.RlpEncode()))
|
trie.Update(string(ethutil.NewValue(i).Encode()), string(ethutil.NewValue(receipt.RlpData()).Encode()))
|
||||||
}
|
}
|
||||||
|
|
||||||
switch trie.Root.(type) {
|
switch trie.Root.(type) {
|
||||||
case string:
|
case string:
|
||||||
block.TxSha = []byte(trie.Root.(string))
|
sha = []byte(trie.Root.(string))
|
||||||
case []byte:
|
case []byte:
|
||||||
block.TxSha = trie.Root.([]byte)
|
sha = trie.Root.([]byte)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("invalid root type %T", trie.Root))
|
panic(fmt.Sprintf("invalid root type %T", trie.Root))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return sha
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Block) SetTxHash(receipts Receipts) {
|
||||||
|
self.TxSha = CreateTxSha(receipts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (block *Block) Value() *ethutil.Value {
|
func (block *Block) Value() *ethutil.Value {
|
||||||
|
|
|
@ -201,11 +201,16 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
|
||||||
fmt.Printf("## %x %x ##\n", block.Hash(), block.Number)
|
fmt.Printf("## %x %x ##\n", block.Hash(), block.Number)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = sm.ApplyDiff(state, parent, block)
|
receipts, err := sm.ApplyDiff(state, parent, block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
txSha := CreateTxSha(receipts)
|
||||||
|
if bytes.Compare(txSha, block.TxSha) != 0 {
|
||||||
|
return fmt.Errorf("Error validating tx sha. Received %x, got %x", block.TxSha, txSha)
|
||||||
|
}
|
||||||
|
|
||||||
// Block validation
|
// Block validation
|
||||||
if err = sm.ValidateBlock(block); err != nil {
|
if err = sm.ValidateBlock(block); err != nil {
|
||||||
statelogger.Errorln("Error validating block:", err)
|
statelogger.Errorln("Error validating block:", err)
|
||||||
|
@ -219,17 +224,7 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if ethutil.Config.Paranoia {
|
|
||||||
valid, _ := ethtrie.ParanoiaCheck(state.trie)
|
|
||||||
if !valid {
|
|
||||||
err = fmt.Errorf("PARANOIA: World state trie corruption")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if !block.State().Cmp(state) {
|
if !block.State().Cmp(state) {
|
||||||
|
|
||||||
err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
|
err = fmt.Errorf("Invalid merkle root.\nrec: %x\nis: %x", block.State().trie.Root, state.trie.Root)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,7 @@ func (self *Miner) mineNewBlock() {
|
||||||
logger.Debugln(err)
|
logger.Debugln(err)
|
||||||
}
|
}
|
||||||
self.txs = append(txs, unhandledTxs...)
|
self.txs = append(txs, unhandledTxs...)
|
||||||
|
self.block.SetTxHash(receipts)
|
||||||
|
|
||||||
// Set the transactions to the block so the new SHA3 can be calculated
|
// Set the transactions to the block so the new SHA3 can be calculated
|
||||||
self.block.SetReceipts(receipts, txs)
|
self.block.SetReceipts(receipts, txs)
|
||||||
|
|
Loading…
Reference in New Issue