fix: add the mutation of coinbase address under clique mode (#126)

fix clique coinbase issue
This commit is contained in:
Ho 2022-07-21 16:00:50 +08:00 committed by GitHub
parent 3682e05f3f
commit 37dbb86aa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 44772 additions and 16 deletions

View file

@ -704,16 +704,27 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
} }
state.StartPrefetcher("miner") state.StartPrefetcher("miner")
// fetch coinbase's proof proofs := make(map[string][]hexutil.Bytes)
proof, err := state.GetProof(header.Coinbase) // init proof with coinbase's proof
for _, coinbase := range []common.Address{w.coinbase, header.Coinbase} {
if coinbase == (common.Address{}) {
continue
}
key := coinbase.String()
if _, exist := proofs[key]; !exist {
proof, err := state.GetProof(coinbase)
if err != nil { if err != nil {
log.Error("Proof for coinbase not available", "coinbase", header.Coinbase.String(), "error", err) log.Error("Proof for coinbase not available", "coinbase", coinbase, "error", err)
// but we still mark the proofs map with nil array // but we still mark the proofs map with nil array
} }
wrappedProof := make([]hexutil.Bytes, len(proof)) wrappedProof := make([]hexutil.Bytes, len(proof))
for i, bt := range proof { for i, bt := range proof {
wrappedProof[i] = bt wrappedProof[i] = bt
} }
proofs[key] = wrappedProof
}
}
env := &environment{ env := &environment{
signer: types.MakeSigner(w.chainConfig, header.Number), signer: types.MakeSigner(w.chainConfig, header.Number),
@ -722,7 +733,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
family: mapset.NewSet(), family: mapset.NewSet(),
uncles: mapset.NewSet(), uncles: mapset.NewSet(),
header: header, header: header,
proofs: map[string][]hexutil.Bytes{header.Coinbase.String(): wrappedProof}, proofs: proofs,
storageProofs: make(map[string]map[string][]hexutil.Bytes), storageProofs: make(map[string]map[string][]hexutil.Bytes),
} }
// when 08 is processed ancestors contain 07 (quick block) // when 08 is processed ancestors contain 07 (quick block)
@ -842,12 +853,12 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
} }
// collect affected account after tx being applied // collect affected account after tx being applied
for _, acc := range []*common.Address{&from, to} { for acc := range map[common.Address]bool{from: true, (*to): true, w.coinbase: true} {
after = append(after, &types.AccountWrapper{ after = append(after, &types.AccountWrapper{
Address: *acc, Address: acc,
Nonce: w.current.state.GetNonce(*acc), Nonce: w.current.state.GetNonce(acc),
Balance: (*hexutil.Big)(w.current.state.GetBalance(*acc)), Balance: (*hexutil.Big)(w.current.state.GetBalance(acc)),
CodeHash: w.current.state.GetCodeHash(*acc), CodeHash: w.current.state.GetCodeHash(acc),
}) })
} }

44734
trie/zkproof/delete_trace.json Normal file

File diff suppressed because one or more lines are too long

View file

@ -357,7 +357,7 @@ func (w *zktrieProofWriter) traceAccountUpdate(addr common.Address, updateAccDat
var proof proofList var proof proofList
if err := w.tracingZktrie.Prove(addr.Bytes32(), 0, &proof); err != nil { if err := w.tracingZktrie.Prove(addr.Bytes32(), 0, &proof); err != nil {
return nil, fmt.Errorf("prove BEFORE state fail: %s", err) return nil, fmt.Errorf("prove BEFORE state for <%x> fail: %s", addr.Bytes(), err)
} }
decodeProofForMPTPath(proof, out.AccountPath[0]) decodeProofForMPTPath(proof, out.AccountPath[0])

View file

@ -171,6 +171,17 @@ func TestFailedCallTx(t *testing.T) {
} }
//notice: now only work with OP_ORDER=2
func TestDeleteTx(t *testing.T) {
trace := loadStaff(t, "delete_trace.json")
traces, err := HandleBlockResult(trace)
outObj, _ := json.Marshal(traces)
t.Log(string(outObj))
if err != nil {
t.Fatal(err)
}
}
func TestMutipleTx(t *testing.T) { func TestMutipleTx(t *testing.T) {
trace := loadStaff(t, "multi_txs.json") trace := loadStaff(t, "multi_txs.json")
traces, err := HandleBlockResult(trace) traces, err := HandleBlockResult(trace)