Skip to content

Commit

Permalink
fix: add the mutation of coinbase address under clique mode (ethereum…
Browse files Browse the repository at this point in the history
…#126)

fix clique coinbase issue
  • Loading branch information
noel2004 authored Jul 21, 2022
1 parent 3682e05 commit 37dbb86
Show file tree
Hide file tree
Showing 4 changed files with 44,772 additions and 16 deletions.
41 changes: 26 additions & 15 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,15 +704,26 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
}
state.StartPrefetcher("miner")

// fetch coinbase's proof
proof, err := state.GetProof(header.Coinbase)
if err != nil {
log.Error("Proof for coinbase not available", "coinbase", header.Coinbase.String(), "error", err)
// but we still mark the proofs map with nil array
}
wrappedProof := make([]hexutil.Bytes, len(proof))
for i, bt := range proof {
wrappedProof[i] = bt
proofs := make(map[string][]hexutil.Bytes)
// 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 {
log.Error("Proof for coinbase not available", "coinbase", coinbase, "error", err)
// but we still mark the proofs map with nil array
}
wrappedProof := make([]hexutil.Bytes, len(proof))
for i, bt := range proof {
wrappedProof[i] = bt
}
proofs[key] = wrappedProof
}
}

env := &environment{
Expand All @@ -722,7 +733,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
family: mapset.NewSet(),
uncles: mapset.NewSet(),
header: header,
proofs: map[string][]hexutil.Bytes{header.Coinbase.String(): wrappedProof},
proofs: proofs,
storageProofs: make(map[string]map[string][]hexutil.Bytes),
}
// when 08 is processed ancestors contain 07 (quick block)
Expand Down Expand Up @@ -842,12 +853,12 @@ func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Addres
}

// 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{
Address: *acc,
Nonce: w.current.state.GetNonce(*acc),
Balance: (*hexutil.Big)(w.current.state.GetBalance(*acc)),
CodeHash: w.current.state.GetCodeHash(*acc),
Address: acc,
Nonce: w.current.state.GetNonce(acc),
Balance: (*hexutil.Big)(w.current.state.GetBalance(acc)),
CodeHash: w.current.state.GetCodeHash(acc),
})
}

Expand Down
44,734 changes: 44,734 additions & 0 deletions trie/zkproof/delete_trace.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion trie/zkproof/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (w *zktrieProofWriter) traceAccountUpdate(addr common.Address, updateAccDat

var proof proofList
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])
Expand Down
11 changes: 11 additions & 0 deletions trie/zkproof/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
trace := loadStaff(t, "multi_txs.json")
traces, err := HandleBlockResult(trace)
Expand Down

0 comments on commit 37dbb86

Please sign in to comment.