From eef27d37ee92400ad2f7d300ef247ebdb3b471aa Mon Sep 17 00:00:00 2001 From: tom <69969590+simlecode@users.noreply.github.com> Date: Wed, 11 May 2022 17:51:28 +0800 Subject: [PATCH] feat: api: add StateGetNetworkParmas (#4875) * add StateGetNetworkParmas api --- app/submodule/chain/chaininfo_api.go | 39 +++++++++++++++++ venus-shared/api/chain/v0/chain.go | 2 + venus-shared/api/chain/v0/method.md | 43 +++++++++++++++++++ .../api/chain/v0/mock/mock_fullnode.go | 15 +++++++ venus-shared/api/chain/v0/proxy_gen.go | 4 ++ venus-shared/api/chain/v1/chain.go | 2 + venus-shared/api/chain/v1/method.md | 43 +++++++++++++++++++ .../api/chain/v1/mock/mock_fullnode.go | 15 +++++++ venus-shared/api/chain/v1/proxy_gen.go | 4 ++ venus-shared/compatible-checks/api-diff.txt | 2 + venus-shared/compatible-checks/api-perm.txt | 2 + venus-shared/types/api_types.go | 31 +++++++++++++ 12 files changed, 202 insertions(+) diff --git a/app/submodule/chain/chaininfo_api.go b/app/submodule/chain/chaininfo_api.go index 3ca4cfeee4..6e1709b92b 100644 --- a/app/submodule/chain/chaininfo_api.go +++ b/app/submodule/chain/chaininfo_api.go @@ -606,3 +606,42 @@ func (cia *chainInfoAPI) ChainGetPath(ctx context.Context, from types.TipSetKey, } return path, nil } + +// StateGetNetworkParams returns current network params +func (cia *chainInfoAPI) StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) { + networkName, err := cia.getNetworkName(ctx) + if err != nil { + return nil, err + } + cfg := cia.chain.config.Repo().Config() + params := &types.NetworkParams{ + NetworkName: types.NetworkName(networkName), + BlockDelaySecs: cfg.NetworkParams.BlockDelay, + ConsensusMinerMinPower: abi.NewStoragePower(int64(cfg.NetworkParams.ConsensusMinerMinPower)), + SupportedProofTypes: cfg.NetworkParams.ReplaceProofTypes, + PreCommitChallengeDelay: cfg.NetworkParams.PreCommitChallengeDelay, + ForkUpgradeParams: types.ForkUpgradeParams{ + UpgradeSmokeHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeSmokeHeight, + UpgradeBreezeHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeBreezeHeight, + UpgradeIgnitionHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeIgnitionHeight, + UpgradeLiftoffHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeLiftoffHeight, + UpgradeAssemblyHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeAssemblyHeight, + UpgradeRefuelHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeRefuelHeight, + UpgradeTapeHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeTapeHeight, + UpgradeKumquatHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeKumquatHeight, + BreezeGasTampingDuration: cfg.NetworkParams.ForkUpgradeParam.BreezeGasTampingDuration, + UpgradeCalicoHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeCalicoHeight, + UpgradePersianHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradePersianHeight, + UpgradeOrangeHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeOrangeHeight, + UpgradeClausHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeClausHeight, + UpgradeTrustHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeTrustHeight, + UpgradeNorwegianHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeNorwegianHeight, + UpgradeTurboHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeTurboHeight, + UpgradeHyperdriveHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeHyperdriveHeight, + UpgradeChocolateHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeChocolateHeight, + UpgradeOhSnapHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeOhSnapHeight, + }, + } + + return params, nil +} diff --git a/venus-shared/api/chain/v0/chain.go b/venus-shared/api/chain/v0/chain.go index 29f2fc6f20..ece12ff897 100644 --- a/venus-shared/api/chain/v0/chain.go +++ b/venus-shared/api/chain/v0/chain.go @@ -74,6 +74,8 @@ type IChainInfo interface { VerifyEntry(parent, child *types.BeaconEntry, height abi.ChainEpoch) bool //perm:read ChainExport(context.Context, abi.ChainEpoch, bool, types.TipSetKey) (<-chan []byte, error) //perm:read ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*types.HeadChange, error) //perm:read + // StateGetNetworkParams return current network params + StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) //perm:read } type IMinerState interface { diff --git a/venus-shared/api/chain/v0/method.md b/venus-shared/api/chain/v0/method.md index b3544e99d4..2b93cdc668 100644 --- a/venus-shared/api/chain/v0/method.md +++ b/venus-shared/api/chain/v0/method.md @@ -38,6 +38,7 @@ * [MessageWait](#MessageWait) * [ProtocolParameters](#ProtocolParameters) * [ResolveToKeyAddr](#ResolveToKeyAddr) + * [StateGetNetworkParams](#StateGetNetworkParams) * [StateGetReceipt](#StateGetReceipt) * [StateNetworkName](#StateNetworkName) * [StateNetworkVersion](#StateNetworkVersion) @@ -1243,6 +1244,48 @@ Inputs: Response: `"f01234"` +### StateGetNetworkParams +StateGetNetworkParams return current network params + + +Perms: read + +Inputs: `[]` + +Response: +```json +{ + "NetworkName": "mainnet", + "BlockDelaySecs": 42, + "ConsensusMinerMinPower": "0", + "SupportedProofTypes": [ + 8 + ], + "PreCommitChallengeDelay": 10101, + "ForkUpgradeParams": { + "UpgradeSmokeHeight": 10101, + "UpgradeBreezeHeight": 10101, + "UpgradeIgnitionHeight": 10101, + "UpgradeLiftoffHeight": 10101, + "UpgradeAssemblyHeight": 10101, + "UpgradeRefuelHeight": 10101, + "UpgradeTapeHeight": 10101, + "UpgradeKumquatHeight": 10101, + "BreezeGasTampingDuration": 10101, + "UpgradeCalicoHeight": 10101, + "UpgradePersianHeight": 10101, + "UpgradeOrangeHeight": 10101, + "UpgradeClausHeight": 10101, + "UpgradeTrustHeight": 10101, + "UpgradeNorwegianHeight": 10101, + "UpgradeTurboHeight": 10101, + "UpgradeHyperdriveHeight": 10101, + "UpgradeChocolateHeight": 10101, + "UpgradeOhSnapHeight": 10101 + } +} +``` + ### StateGetReceipt diff --git a/venus-shared/api/chain/v0/mock/mock_fullnode.go b/venus-shared/api/chain/v0/mock/mock_fullnode.go index e738bc6aa3..927d38ce09 100644 --- a/venus-shared/api/chain/v0/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v0/mock/mock_fullnode.go @@ -1622,6 +1622,21 @@ func (mr *MockFullNodeMockRecorder) StateGetActor(arg0, arg1, arg2 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetActor", reflect.TypeOf((*MockFullNode)(nil).StateGetActor), arg0, arg1, arg2) } +// StateGetNetworkParams mocks base method. +func (m *MockFullNode) StateGetNetworkParams(arg0 context.Context) (*types.NetworkParams, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateGetNetworkParams", arg0) + ret0, _ := ret[0].(*types.NetworkParams) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateGetNetworkParams indicates an expected call of StateGetNetworkParams. +func (mr *MockFullNodeMockRecorder) StateGetNetworkParams(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetNetworkParams", reflect.TypeOf((*MockFullNode)(nil).StateGetNetworkParams), arg0) +} + // StateGetReceipt mocks base method. func (m *MockFullNode) StateGetReceipt(arg0 context.Context, arg1 cid.Cid, arg2 types.TipSetKey) (*types.MessageReceipt, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v0/proxy_gen.go b/venus-shared/api/chain/v0/proxy_gen.go index 8470798c0f..6c74e2885f 100644 --- a/venus-shared/api/chain/v0/proxy_gen.go +++ b/venus-shared/api/chain/v0/proxy_gen.go @@ -230,6 +230,7 @@ type IChainInfoStruct struct { MessageWait func(ctx context.Context, msgCid cid.Cid, confidence, lookback abi.ChainEpoch) (*types.ChainMessage, error) `perm:"read"` ProtocolParameters func(ctx context.Context) (*types.ProtocolParams, error) `perm:"read"` ResolveToKeyAddr func(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) `perm:"read"` + StateGetNetworkParams func(ctx context.Context) (*types.NetworkParams, error) `perm:"read"` StateGetReceipt func(ctx context.Context, msg cid.Cid, from types.TipSetKey) (*types.MessageReceipt, error) `perm:"read"` StateNetworkName func(ctx context.Context) (types.NetworkName, error) `perm:"read"` StateNetworkVersion func(ctx context.Context, tsk types.TipSetKey) (network.Version, error) `perm:"read"` @@ -318,6 +319,9 @@ func (s *IChainInfoStruct) ProtocolParameters(p0 context.Context) (*types.Protoc func (s *IChainInfoStruct) ResolveToKeyAddr(p0 context.Context, p1 address.Address, p2 *types.TipSet) (address.Address, error) { return s.Internal.ResolveToKeyAddr(p0, p1, p2) } +func (s *IChainInfoStruct) StateGetNetworkParams(p0 context.Context) (*types.NetworkParams, error) { + return s.Internal.StateGetNetworkParams(p0) +} func (s *IChainInfoStruct) StateGetReceipt(p0 context.Context, p1 cid.Cid, p2 types.TipSetKey) (*types.MessageReceipt, error) { return s.Internal.StateGetReceipt(p0, p1, p2) } diff --git a/venus-shared/api/chain/v1/chain.go b/venus-shared/api/chain/v1/chain.go index 28023d31be..9212fa66be 100644 --- a/venus-shared/api/chain/v1/chain.go +++ b/venus-shared/api/chain/v1/chain.go @@ -108,6 +108,8 @@ type IChainInfo interface { VerifyEntry(parent, child *types.BeaconEntry, height abi.ChainEpoch) bool //perm:read ChainExport(context.Context, abi.ChainEpoch, bool, types.TipSetKey) (<-chan []byte, error) //perm:read ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*types.HeadChange, error) //perm:read + // StateGetNetworkParams return current network params + StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) //perm:read } type IMinerState interface { diff --git a/venus-shared/api/chain/v1/method.md b/venus-shared/api/chain/v1/method.md index 6d5d4a1840..5cca6db881 100644 --- a/venus-shared/api/chain/v1/method.md +++ b/venus-shared/api/chain/v1/method.md @@ -39,6 +39,7 @@ * [MessageWait](#MessageWait) * [ProtocolParameters](#ProtocolParameters) * [ResolveToKeyAddr](#ResolveToKeyAddr) + * [StateGetNetworkParams](#StateGetNetworkParams) * [StateGetRandomnessFromBeacon](#StateGetRandomnessFromBeacon) * [StateGetRandomnessFromTickets](#StateGetRandomnessFromTickets) * [StateNetworkName](#StateNetworkName) @@ -1275,6 +1276,48 @@ Inputs: Response: `"f01234"` +### StateGetNetworkParams +StateGetNetworkParams return current network params + + +Perms: read + +Inputs: `[]` + +Response: +```json +{ + "NetworkName": "mainnet", + "BlockDelaySecs": 42, + "ConsensusMinerMinPower": "0", + "SupportedProofTypes": [ + 8 + ], + "PreCommitChallengeDelay": 10101, + "ForkUpgradeParams": { + "UpgradeSmokeHeight": 10101, + "UpgradeBreezeHeight": 10101, + "UpgradeIgnitionHeight": 10101, + "UpgradeLiftoffHeight": 10101, + "UpgradeAssemblyHeight": 10101, + "UpgradeRefuelHeight": 10101, + "UpgradeTapeHeight": 10101, + "UpgradeKumquatHeight": 10101, + "BreezeGasTampingDuration": 10101, + "UpgradeCalicoHeight": 10101, + "UpgradePersianHeight": 10101, + "UpgradeOrangeHeight": 10101, + "UpgradeClausHeight": 10101, + "UpgradeTrustHeight": 10101, + "UpgradeNorwegianHeight": 10101, + "UpgradeTurboHeight": 10101, + "UpgradeHyperdriveHeight": 10101, + "UpgradeChocolateHeight": 10101, + "UpgradeOhSnapHeight": 10101 + } +} +``` + ### StateGetRandomnessFromBeacon diff --git a/venus-shared/api/chain/v1/mock/mock_fullnode.go b/venus-shared/api/chain/v1/mock/mock_fullnode.go index 436303d312..b61088e7c6 100644 --- a/venus-shared/api/chain/v1/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v1/mock/mock_fullnode.go @@ -1682,6 +1682,21 @@ func (mr *MockFullNodeMockRecorder) StateGetActor(arg0, arg1, arg2 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetActor", reflect.TypeOf((*MockFullNode)(nil).StateGetActor), arg0, arg1, arg2) } +// StateGetNetworkParams mocks base method. +func (m *MockFullNode) StateGetNetworkParams(arg0 context.Context) (*types.NetworkParams, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateGetNetworkParams", arg0) + ret0, _ := ret[0].(*types.NetworkParams) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateGetNetworkParams indicates an expected call of StateGetNetworkParams. +func (mr *MockFullNodeMockRecorder) StateGetNetworkParams(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetNetworkParams", reflect.TypeOf((*MockFullNode)(nil).StateGetNetworkParams), arg0) +} + // StateGetRandomnessFromBeacon mocks base method. func (m *MockFullNode) StateGetRandomnessFromBeacon(arg0 context.Context, arg1 crypto.DomainSeparationTag, arg2 abi.ChainEpoch, arg3 []byte, arg4 types.TipSetKey) (abi.Randomness, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v1/proxy_gen.go b/venus-shared/api/chain/v1/proxy_gen.go index 24e6290fa9..39efca3882 100644 --- a/venus-shared/api/chain/v1/proxy_gen.go +++ b/venus-shared/api/chain/v1/proxy_gen.go @@ -231,6 +231,7 @@ type IChainInfoStruct struct { MessageWait func(ctx context.Context, msgCid cid.Cid, confidence, lookback abi.ChainEpoch) (*types.ChainMessage, error) `perm:"read"` ProtocolParameters func(ctx context.Context) (*types.ProtocolParams, error) `perm:"read"` ResolveToKeyAddr func(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) `perm:"read"` + StateGetNetworkParams func(ctx context.Context) (*types.NetworkParams, error) `perm:"read"` StateGetRandomnessFromBeacon func(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) `perm:"read"` StateGetRandomnessFromTickets func(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) `perm:"read"` StateNetworkName func(ctx context.Context) (types.NetworkName, error) `perm:"read"` @@ -321,6 +322,9 @@ func (s *IChainInfoStruct) ProtocolParameters(p0 context.Context) (*types.Protoc func (s *IChainInfoStruct) ResolveToKeyAddr(p0 context.Context, p1 address.Address, p2 *types.TipSet) (address.Address, error) { return s.Internal.ResolveToKeyAddr(p0, p1, p2) } +func (s *IChainInfoStruct) StateGetNetworkParams(p0 context.Context) (*types.NetworkParams, error) { + return s.Internal.StateGetNetworkParams(p0) +} func (s *IChainInfoStruct) StateGetRandomnessFromBeacon(p0 context.Context, p1 crypto.DomainSeparationTag, p2 abi.ChainEpoch, p3 []byte, p4 types.TipSetKey) (abi.Randomness, error) { return s.Internal.StateGetRandomnessFromBeacon(p0, p1, p2, p3, p4) } diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index d61117990a..97b59de280 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -126,6 +126,7 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v0.FullNode <> github.c > StateDealProviderCollateralBounds {[func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (types.DealCollateralBounds, error) <> func(context.Context, abi.PaddedPieceSize, bool, types.TipSetKey) (api.DealCollateralBounds, error)] base=func in type: #3 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} - StateDecodeParams > StateGetActor {[func(context.Context, address.Address, types.TipSetKey) (*internal.Actor, error) <> func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} + + StateGetNetworkParams - StateGetRandomnessFromBeacon - StateGetRandomnessFromTickets > StateGetReceipt {[func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) <> func(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} @@ -322,6 +323,7 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c - StateDecodeParams - StateEncodeParams > StateGetActor {[func(context.Context, address.Address, types.TipSetKey) (*internal.Actor, error) <> func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} + + StateGetNetworkParams > StateGetRandomnessFromBeacon {[func(context.Context, crypto.DomainSeparationTag, abi.ChainEpoch, []uint8, types.TipSetKey) (abi.Randomness, error) <> func(context.Context, crypto.DomainSeparationTag, abi.ChainEpoch, []uint8, types.TipSetKey) (abi.Randomness, error)] base=func in type: #4 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} > StateGetRandomnessFromTickets {[func(context.Context, crypto.DomainSeparationTag, abi.ChainEpoch, []uint8, types.TipSetKey) (abi.Randomness, error) <> func(context.Context, crypto.DomainSeparationTag, abi.ChainEpoch, []uint8, types.TipSetKey) (abi.Randomness, error)] base=func in type: #4 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} > StateListActors {[func(context.Context, types.TipSetKey) ([]address.Address, error) <> func(context.Context, types.TipSetKey) ([]address.Address, error)] base=func in type: #1 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}} diff --git a/venus-shared/compatible-checks/api-perm.txt b/venus-shared/compatible-checks/api-perm.txt index a815fbdead..e618b57e9b 100644 --- a/venus-shared/compatible-checks/api-perm.txt +++ b/venus-shared/compatible-checks/api-perm.txt @@ -10,6 +10,7 @@ v0: github.com/filecoin-project/venus/venus-shared/api/chain/v0 <> github.com/fi - IChainInfo.MessageWait - IChainInfo.ProtocolParameters - IChainInfo.ResolveToKeyAddr + - IChainInfo.StateGetNetworkParams - IChainInfo.VerifyEntry - IMinerState.StateMinerSectorSize - IMinerState.StateMinerWorkerAddress @@ -55,6 +56,7 @@ v1: github.com/filecoin-project/venus/venus-shared/api/chain/v1 <> github.com/fi - IChainInfo.MessageWait - IChainInfo.ProtocolParameters - IChainInfo.ResolveToKeyAddr + - IChainInfo.StateGetNetworkParams - IChainInfo.VerifyEntry - IMinerState.StateMinerSectorSize - IMinerState.StateMinerWorkerAddress diff --git a/venus-shared/types/api_types.go b/venus-shared/types/api_types.go index ccf307fdc9..663725f1bd 100644 --- a/venus-shared/types/api_types.go +++ b/venus-shared/types/api_types.go @@ -281,3 +281,34 @@ type InvocResult struct { Error string Duration time.Duration } + +type NetworkParams struct { + NetworkName NetworkName + BlockDelaySecs uint64 + ConsensusMinerMinPower abi.StoragePower + SupportedProofTypes []abi.RegisteredSealProof + PreCommitChallengeDelay abi.ChainEpoch + ForkUpgradeParams ForkUpgradeParams +} + +type ForkUpgradeParams struct { + UpgradeSmokeHeight abi.ChainEpoch + UpgradeBreezeHeight abi.ChainEpoch + UpgradeIgnitionHeight abi.ChainEpoch + UpgradeLiftoffHeight abi.ChainEpoch + UpgradeAssemblyHeight abi.ChainEpoch + UpgradeRefuelHeight abi.ChainEpoch + UpgradeTapeHeight abi.ChainEpoch + UpgradeKumquatHeight abi.ChainEpoch + BreezeGasTampingDuration abi.ChainEpoch + UpgradeCalicoHeight abi.ChainEpoch + UpgradePersianHeight abi.ChainEpoch + UpgradeOrangeHeight abi.ChainEpoch + UpgradeClausHeight abi.ChainEpoch + UpgradeTrustHeight abi.ChainEpoch + UpgradeNorwegianHeight abi.ChainEpoch + UpgradeTurboHeight abi.ChainEpoch + UpgradeHyperdriveHeight abi.ChainEpoch + UpgradeChocolateHeight abi.ChainEpoch + UpgradeOhSnapHeight abi.ChainEpoch +}