Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/eth block unclehash #5700

Merged
merged 4 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ func (a *ethAPI) EthGetCode(ctx context.Context, ethAddr types.EthAddress, blkPa
return nil, fmt.Errorf("cannot parse block param: %s", blkParam)
}

// StateManager.Call will panic if there is no parent
if ts.Height() == 0 {
return nil, fmt.Errorf("block param must not specify genesis block")
}

// Try calling until we find a height with no migration.
var res *vm.Ret
for {
Expand Down Expand Up @@ -574,7 +579,7 @@ func (a *ethAPI) EthFeeHistory(ctx context.Context, blkCount types.EthUint64, ne
}

return types.EthFeeHistory{
OldestBlock: oldestBlkHeight,
OldestBlock: types.EthUint64(oldestBlkHeight),
BaseFeePerGas: baseFeeArray,
GasUsedRatio: gasUsedRatioArray,
}, nil
Expand Down Expand Up @@ -945,7 +950,7 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx
return types.EthBlock{}, fmt.Errorf("error loading messages for tipset: %v: %w", ts, err)
}

block := types.NewEthBlock()
block := types.NewEthBlock(len(msgs) > 0)

// this seems to be a very expensive way to get gasUsed of the block. may need to find an efficient way to do it
gasUsed := int64(0)
Expand Down
27 changes: 17 additions & 10 deletions venus-shared/actors/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ type EthBlock struct {
GasLimit EthUint64 `json:"gasLimit"`
GasUsed EthUint64 `json:"gasUsed"`
Timestamp EthUint64 `json:"timestamp"`
Extradata []byte `json:"extraData"`
Extradata EthBytes `json:"extraData"`
MixHash EthHash `json:"mixHash"`
Nonce EthNonce `json:"nonce"`
BaseFeePerGas EthBigInt `json:"baseFeePerGas"`
Expand All @@ -164,17 +164,19 @@ type EthBlock struct {
}

var (
EmptyEthBloom = [256]byte{}
EmptyEthHash = EthHash{}
EmptyEthInt = EthUint64(0)
EmptyEthNonce = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
EmptyEthBloom = [256]byte{}
EmptyEthHash = EthHash{}
EmptyUncleHash = One(ParseEthHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")) // Keccak-256 of an RLP of an empty array
EmptyRootHash = One(ParseEthHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")) // Keccak-256 hash of the RLP of null
EmptyEthInt = EthUint64(0)
EmptyEthNonce = [8]byte{0, 0, 0, 0, 0, 0, 0, 0}
)

func NewEthBlock() EthBlock {
return EthBlock{
Sha3Uncles: EmptyEthHash,
func NewEthBlock(hasTransactions bool) EthBlock {
b := EthBlock{
Sha3Uncles: EmptyUncleHash, // Sha3Uncles set to a hardcoded value which is used by some clients to determine if has no uncles.,
StateRoot: EmptyEthHash,
TransactionsRoot: EmptyEthHash,
TransactionsRoot: EmptyRootHash, // TransactionsRoot set to a hardcoded value which is used by some clients to determine if has no transactions.,
ReceiptsRoot: EmptyEthHash,
Difficulty: EmptyEthInt,
LogsBloom: EmptyEthBloom[:],
Expand All @@ -185,6 +187,11 @@ func NewEthBlock() EthBlock {
Uncles: []EthHash{},
Transactions: []interface{}{},
}
if hasTransactions {
b.TransactionsRoot = EmptyEthHash
}

return b
}

type EthCall struct {
Expand Down Expand Up @@ -473,7 +480,7 @@ func EthHashFromTxBytes(b []byte) EthHash {
}

type EthFeeHistory struct {
OldestBlock uint64 `json:"oldestBlock"`
OldestBlock EthUint64 `json:"oldestBlock"`
BaseFeePerGas []EthBigInt `json:"baseFeePerGas"`
GasUsedRatio []float64 `json:"gasUsedRatio"`
Reward *[][]EthBigInt `json:"reward,omitempty"`
Expand Down
12 changes: 12 additions & 0 deletions venus-shared/actors/types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,18 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version)
return fmt.Errorf("invalid 'To' address")
}

if !abi.AddressValidForNetworkVersion(m.To, version) {
return fmt.Errorf("'To' address protocol unsupported for network version")
}

if m.From == address.Undef {
return fmt.Errorf("'From' address cannot be empty")
}

if !abi.AddressValidForNetworkVersion(m.From, version) {
return fmt.Errorf("'From' address protocol unsupported for network version")
}

if m.Value.Int == nil {
return fmt.Errorf("'Value' cannot be nil")
}
Expand Down Expand Up @@ -193,6 +201,10 @@ func (m *Message) ValidForBlockInclusion(minGas int64, version network.Version)
return fmt.Errorf("'GasLimit' field cannot be greater than a block's gas limit")
}

if m.GasLimit <= 0 {
return fmt.Errorf("'GasLimit' field %d must be positive", m.GasLimit)
}

// since prices might vary with time, this is technically semantic validation
if m.GasLimit < minGas {
return fmt.Errorf("'GasLimit' field cannot be less than the cost of storing a message on chain %d < %d", m.GasLimit, minGas)
Expand Down
9 changes: 4 additions & 5 deletions venus-shared/actors/types/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ var bigZero = big.Zero()

var TotalFilecoinInt = FromFil(params.FilBase)

var ZeroAddress = func() address.Address {
addr := "f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a"
var ZeroAddress address.Address = One(address.NewFromString("f3yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaby2smx7a"))

ret, err := address.NewFromString(addr)
func One[R any](r R, err error) R {
if err != nil {
panic(err)
}

return ret
}()
return r
}
6 changes: 3 additions & 3 deletions venus-shared/api/chain/v1/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ Inputs:
Response:
```json
{
"oldestBlock": 42,
"oldestBlock": "0x5",
"baseFeePerGas": [
"0x0"
],
Expand Down Expand Up @@ -2270,7 +2270,7 @@ Response:
"gasLimit": "0x5",
"gasUsed": "0x5",
"timestamp": "0x5",
"extraData": "Ynl0ZSBhcnJheQ==",
"extraData": "0x07",
"mixHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"nonce": "0x0707070707070707",
"baseFeePerGas": "0x0",
Expand Down Expand Up @@ -2314,7 +2314,7 @@ Response:
"gasLimit": "0x5",
"gasUsed": "0x5",
"timestamp": "0x5",
"extraData": "Ynl0ZSBhcnJheQ==",
"extraData": "0x07",
"mixHash": "0x0707070707070707070707070707070707070707070707070707070707070707",
"nonce": "0x0707070707070707",
"baseFeePerGas": "0x0",
Expand Down
3 changes: 3 additions & 0 deletions venus-shared/compatible-checks/api-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
+ Concurrent
- CreateBackup
- Discover
> EthFeeHistory {[func(context.Context, types.EthUint64, string, []float64) (types.EthFeeHistory, error) <> func(context.Context, ethtypes.EthUint64, string, []float64) (ethtypes.EthFeeHistory, error)] base=func out type: #0 input; nested={[types.EthFeeHistory <> ethtypes.EthFeeHistory] base=struct field; nested={[types.EthFeeHistory <> ethtypes.EthFeeHistory] base=exported field type: #0 field named OldestBlock; nested={[types.EthUint64 <> uint64] base=codec marshaler implementations for codec JSON: true != false; nested=nil}}}}
> EthGetBlockByHash {[func(context.Context, types.EthHash, bool) (types.EthBlock, error) <> func(context.Context, ethtypes.EthHash, bool) (ethtypes.EthBlock, error)] base=func out type: #0 input; nested={[types.EthBlock <> ethtypes.EthBlock] base=struct field; nested={[types.EthBlock <> ethtypes.EthBlock] base=exported field type: #14 field named Extradata; nested={[types.EthBytes <> []uint8] base=codec marshaler implementations for codec JSON: true != false; nested=nil}}}}
> EthGetBlockByNumber {[func(context.Context, string, bool) (types.EthBlock, error) <> func(context.Context, string, bool) (ethtypes.EthBlock, error)] base=func out type: #0 input; nested={[types.EthBlock <> ethtypes.EthBlock] base=struct field; nested={[types.EthBlock <> ethtypes.EthBlock] base=exported field type: #14 field named Extradata; nested={[types.EthBytes <> []uint8] base=codec marshaler implementations for codec JSON: true != false; nested=nil}}}}
+ GasBatchEstimateMessageGas
> GasEstimateMessageGas {[func(context.Context, *types.Message, *types.MessageSendSpec, types.TipSetKey) (*types.Message, error) <> func(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error)] base=func in type: #2 input; nested={[*types.MessageSendSpec <> *api.MessageSendSpec] base=pointed type; nested={[types.MessageSendSpec <> api.MessageSendSpec] base=struct field; nested={[types.MessageSendSpec <> api.MessageSendSpec] base=exported fields count: 3 != 2; nested=nil}}}}
+ GetActor
Expand Down