Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
Support Berlin upgrade AccessListTxType (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
freehere107 authored Apr 20, 2021
1 parent a0ef546 commit 6796933
Show file tree
Hide file tree
Showing 12 changed files with 536 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "darwinia-shadow"
version = "0.4.0"
version = "0.5.0"
authors = ["clearloop <udtrokia@gmail.com>"]
edition = "2018"
description = "The shadow service for relayers and verify workers to retrieve header data and generate proof."
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The shadow service for relayers and verify workers to retrieve header data and g
## Usage

```sh
shadow 0.4.0
shadow 0.5.0

USAGE:
shadow <SUBCOMMAND>
Expand Down
8 changes: 4 additions & 4 deletions api/src/ethereum/mmr_leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ use serde::{Serialize};
/// MMR leaf result
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum MMRLeafResult {
MMRLeaf { mmr_leaf: String },
pub enum MmrLeafResult {
MmrLeaf { mmr_leaf: String },
Error { error: String }
}

/// Get target mmr
#[allow(clippy::eval_order_dependence)]
pub async fn handle(block: Path<String>, app_data: Data<AppData>) -> impl Responder {
match mmr_leaf(block, &app_data.mmr_db) {
Ok(leaf) => Json(MMRLeafResult::MMRLeaf { mmr_leaf: format!("0x{}", leaf) }),
Err(err) => Json(MMRLeafResult::Error { error: err.to_string() })
Ok(leaf) => Json(MmrLeafResult::MmrLeaf { mmr_leaf: format!("0x{}", leaf) }),
Err(err) => Json(MmrLeafResult::Error { error: err.to_string() })
}
}

Expand Down
6 changes: 3 additions & 3 deletions api/src/ethereum/parent_mmr_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Serialize;
/// MMR root result
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
#[serde(untagged)]
pub enum MMRRootResult {
pub enum MmrRootResult {
MmrRoot { mmr_root: String },
Error { error: String }
}
Expand All @@ -19,8 +19,8 @@ pub enum MMRRootResult {
#[allow(clippy::eval_order_dependence)]
pub async fn handle(block: Path<String>, app_data: Data<AppData>) -> impl Responder {
match parent_mmr_root(block, &app_data.mmr_db) {
Ok(root) => Json(MMRRootResult::MmrRoot { mmr_root: format!("0x{}", root) }),
Err(err) => Json(MMRRootResult::Error { error: err.to_string() })
Ok(root) => Json(MmrRootResult::MmrRoot { mmr_root: format!("0x{}", root) }),
Err(err) => Json(MmrRootResult::Error { error: err.to_string() })
}
}

Expand Down
16 changes: 8 additions & 8 deletions ffi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/darwinia-network/shadow/ffi
go 1.14

require (
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/deckarep/golang-set v1.7.1
github.com/edsrzf/mmap-go v1.0.0
github.com/ethereum/go-ethereum v1.9.15
github.com/fatih/color v1.3.0
github.com/ethereum/go-ethereum v1.10.2
github.com/fatih/color v1.7.0
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/golang/snappy v0.0.1
github.com/hashicorp/golang-lru v0.5.4
github.com/golang/snappy v0.0.3-0.20201103224600-674baa8c7fc3
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d
github.com/huandu/xstrings v1.3.2
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mitchellh/mapstructure v1.3.2
Expand All @@ -19,10 +19,10 @@ require (
github.com/prometheus/tsdb v0.7.1 // indirect
github.com/regcostajr/go-web3 v0.0.0-20180609031449-555e83b623dd
github.com/shopspring/decimal v1.2.0
github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.1.0
github.com/tuvistavie/securerandom v0.0.0-20140719024926-15512123a948
golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0
gopkg.in/yaml.v2 v2.2.8 // indirect
golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe // indirect
)
503 changes: 503 additions & 0 deletions ffi/go.sum

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions ffi/pkg/ethashproof/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,17 +562,6 @@ func (ethash *Ethash) Prepare(chain consensus.ChainReader, header *types.Header)
return nil
}

// Finalize implements consensus.Engine, accumulating the block and uncle rewards,
// setting the final state and assembling the block.
func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
// Accumulate any block and uncle rewards and commit the final state root
accumulateRewards(chain.Config(), state, header, uncles)
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))

// Header seems complete, assemble into a block and return
return types.NewBlock(header, txs, uncles, receipts), nil
}

// SealHash returns the hash of a block prior to it being sealed.
func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
hasher := sha3.NewLegacyKeccak256()
Expand Down
26 changes: 9 additions & 17 deletions ffi/pkg/shadow/eth/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,32 +189,24 @@ func GetReceiptRlpEncode(api string, tx string) (*types.Receipt, error) {
func trieFromReceipts(receipts map[string]interface{}) (*trie.Trie, error) {
tr := new(trie.Trie)

for i, r := range receipts {
path, err := rlp.EncodeToBytes(uint(util.StringToInt(i)))
if err != nil {
return nil, err
}
var receiptList types.Receipts
for i := 0; i < len(receipts); i++ {
receiptList = append(receiptList, receipts[util.IntToString(i)].(*types.Receipt))
}

rawReceipt, err := encodeReceipt(r.(*types.Receipt))
for i := range receipts {
path, err := rlp.EncodeToBytes(uint(util.StringToInt(i)))
if err != nil {
return nil, err
}

tr.Update(path, rawReceipt)
w := new(bytes.Buffer)
receiptList.EncodeIndex(util.StringToInt(i), w)
tr.Update(path, w.Bytes())
}

return tr, nil
}

func encodeReceipt(r *types.Receipt) ([]byte, error) {
buf := new(bytes.Buffer)
if err := r.EncodeRLP(buf); err != nil {
return nil, err
}

return buf.Bytes(), nil
}

func rlpLength(dataLen int, offset byte) []byte {
if dataLen < 56 {
return []byte{byte(dataLen) + offset}
Expand Down
6 changes: 3 additions & 3 deletions mmr/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use thiserror::Error;
use anyhow::Result as AnyResult;

#[derive(Error, Debug)]
pub enum MMRError {
pub enum MmrError {
#[error(transparent)]
Io(#[from] std::io::Error),

#[error(transparent)]
CMMRError(#[from] cmmr::Error),
CmmrError(#[from] cmmr::Error),

#[error(transparent)]
MysqlError(#[from] mysql::Error),
Expand All @@ -23,4 +23,4 @@ pub enum MMRError {

}

pub type Result<T> = AnyResult<T, MMRError>;
pub type Result<T> = AnyResult<T, MmrError>;
2 changes: 1 addition & 1 deletion mmr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod mmr_client_trait;
mod mmr_client_for_rocksdb;

pub use self::{
error::{Result, MMRError as Error},
error::{Result, MmrError as Error},
hash::{MergeHash, H256},
rocksdb_store::RocksdbStore,
rocksdb_batchstore::RocksBatchStore,
Expand Down
6 changes: 2 additions & 4 deletions mmr/src/mmr_client_for_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ impl MmrClientTrait for MmrClientForMysql {
fn get_mmr_size(&self) -> Result<u64> {
let mut conn = self.db.get_conn()?;
let mut mmr_size = 0;
if let Some(result) = conn.query_first::<Option<u64>, _>("SELECT MAX(position)+1 FROM mmr")? {
if let Some(count) = result {
mmr_size = count;
}
if let Some(Some(count)) = conn.query_first::<Option<u64>, _>("SELECT MAX(position)+1 FROM mmr")? {
mmr_size = count;
};

Ok(mmr_size)
Expand Down
2 changes: 1 addition & 1 deletion src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::Result as AnyResult;
#[derive(ThisError, Debug)]
pub enum Error {
#[error(transparent)]
IO(#[from] std::io::Error),
Io(#[from] std::io::Error),

#[error(transparent)]
RocksdbError(#[from] rocksdb::Error),
Expand Down

0 comments on commit 6796933

Please sign in to comment.