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

feat: refactor: remove NewestNetworkVersion #9351

Merged
merged 2 commits into from
Sep 21, 2022
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
2 changes: 1 addition & 1 deletion api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func init() {
addExample(&textSelExample)
addExample(&apiSelExample)
addExample(network.ReachabilityPublic)
addExample(build.NewestNetworkVersion)
addExample(build.TestNetworkVersion)
addExample(map[string]int{"name": 42})
addExample(map[string]time.Time{"name": time.Unix(1615243938, 0).UTC()})
addExample(&types.ExecutionTrace{
Expand Down
6 changes: 3 additions & 3 deletions build/params_shared_vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const UnixfsLinksPerLevel = 1024

const AllowableClockDriftSecs = uint64(1)

// TODO: This is still terrible...What's the impact of updating this before mainnet actually upgrades
// Used by tests and some obscure tooling
/* inline-gen template

const NewestNetworkVersion = network.Version{{.latestNetworkVersion}}
const TestNetworkVersion = network.Version{{.latestNetworkVersion}}

/* inline-gen start */

const NewestNetworkVersion = network.Version17
const TestNetworkVersion = network.Version17

/* inline-gen end */

Expand Down
20 changes: 10 additions & 10 deletions chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,11 @@ func (mp *MessagePool) addLocal(ctx context.Context, m *types.SignedMessage) err
// sufficiently.
// For non local messages, if the message cannot be included in the next 20 blocks it returns
// a (soft) validation error.
func (mp *MessagePool) verifyMsgBeforeAdd(m *types.SignedMessage, curTs *types.TipSet, local bool) (bool, error) {
func (mp *MessagePool) verifyMsgBeforeAdd(ctx context.Context, m *types.SignedMessage, curTs *types.TipSet, local bool) (bool, error) {
epoch := curTs.Height() + 1
minGas := vm.PricelistByEpoch(epoch).OnChainMessage(m.ChainLength())

if err := m.VMMessage().ValidForBlockInclusion(minGas.Total(), build.NewestNetworkVersion); err != nil {
if err := m.VMMessage().ValidForBlockInclusion(minGas.Total(), mp.api.StateNetworkVersion(ctx, epoch)); err != nil {
return false, xerrors.Errorf("message will not be included in a block: %w", err)
}

Expand Down Expand Up @@ -671,7 +671,7 @@ func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage) (cid.Ci
done := metrics.Timer(ctx, metrics.MpoolPushDuration)
defer done()

err := mp.checkMessage(m)
err := mp.checkMessage(ctx, m)
if err != nil {
return cid.Undef, err
}
Expand Down Expand Up @@ -705,14 +705,14 @@ func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage) (cid.Ci
return m.Cid(), nil
}

func (mp *MessagePool) checkMessage(m *types.SignedMessage) error {
func (mp *MessagePool) checkMessage(ctx context.Context, m *types.SignedMessage) error {
// big messages are bad, anti DOS
if m.Size() > MaxMessageSize {
return xerrors.Errorf("mpool message too large (%dB): %w", m.Size(), ErrMessageTooBig)
}

// Perform syntactic validation, minGas=0 as we check the actual mingas before we add it
if err := m.Message.ValidForBlockInclusion(0, build.NewestNetworkVersion); err != nil {
if err := m.Message.ValidForBlockInclusion(0, mp.api.StateNetworkVersion(ctx, mp.curTs.Height())); err != nil {
return xerrors.Errorf("message not valid for block inclusion: %w", err)
}

Expand Down Expand Up @@ -740,7 +740,7 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {
done := metrics.Timer(ctx, metrics.MpoolAddDuration)
defer done()

err := mp.checkMessage(m)
err := mp.checkMessage(ctx, m)
if err != nil {
return err
}
Expand Down Expand Up @@ -845,7 +845,7 @@ func (mp *MessagePool) addTs(ctx context.Context, m *types.SignedMessage, curTs
mp.lk.Lock()
defer mp.lk.Unlock()

publish, err := mp.verifyMsgBeforeAdd(m, curTs, local)
publish, err := mp.verifyMsgBeforeAdd(ctx, m, curTs, local)
if err != nil {
return false, err
}
Expand All @@ -870,7 +870,7 @@ func (mp *MessagePool) addTs(ctx context.Context, m *types.SignedMessage, curTs
}

func (mp *MessagePool) addLoaded(ctx context.Context, m *types.SignedMessage) error {
err := mp.checkMessage(m)
err := mp.checkMessage(ctx, m)
if err != nil {
return err
}
Expand All @@ -890,7 +890,7 @@ func (mp *MessagePool) addLoaded(ctx context.Context, m *types.SignedMessage) er
return xerrors.Errorf("minimum expected nonce is %d: %w", snonce, ErrNonceTooLow)
}

_, err = mp.verifyMsgBeforeAdd(m, curTs, true)
_, err = mp.verifyMsgBeforeAdd(ctx, m, curTs, true)
if err != nil {
return err
}
Expand Down Expand Up @@ -1060,7 +1060,7 @@ func (mp *MessagePool) getStateBalance(ctx context.Context, addr address.Address
// - extra strict add checks are used when adding the messages to the msgSet
// that means: no nonce gaps, at most 10 pending messages for the actor
func (mp *MessagePool) PushUntrusted(ctx context.Context, m *types.SignedMessage) (cid.Cid, error) {
err := mp.checkMessage(m)
err := mp.checkMessage(ctx, m)
if err != nil {
return cid.Undef, err
}
Expand Down
6 changes: 6 additions & 0 deletions chain/messagepool/messagepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/network"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/consensus/filcns"
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
"github.com/filecoin-project/lotus/chain/types"
Expand Down Expand Up @@ -166,6 +168,10 @@ func (tma *testMpoolAPI) StateAccountKeyAtFinality(ctx context.Context, addr add
return addr, nil
}

func (tma *testMpoolAPI) StateNetworkVersion(ctx context.Context, h abi.ChainEpoch) network.Version {
return build.TestNetworkVersion
}

func (tma *testMpoolAPI) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
return nil, tma.bmsgs[h.Cid()], nil
}
Expand Down
7 changes: 7 additions & 0 deletions chain/messagepool/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"

"github.com/filecoin-project/lotus/chain/messagesigner"
"github.com/filecoin-project/lotus/chain/stmgr"
Expand All @@ -28,6 +30,7 @@ type Provider interface {
PubSubPublish(string, []byte) error
GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error)
StateAccountKeyAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error)
StateNetworkVersion(context.Context, abi.ChainEpoch) network.Version
MessagesForBlock(context.Context, *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
MessagesForTipset(context.Context, *types.TipSet) ([]types.ChainMsg, error)
LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error)
Expand Down Expand Up @@ -104,6 +107,10 @@ func (mpp *mpoolProvider) StateAccountKeyAtFinality(ctx context.Context, addr ad
return mpp.sm.ResolveToKeyAddressAtFinality(ctx, addr, ts)
}

func (mpp *mpoolProvider) StateNetworkVersion(ctx context.Context, height abi.ChainEpoch) network.Version {
return mpp.sm.GetNetworkVersion(ctx, height)
}

func (mpp *mpoolProvider) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
return mpp.sm.ChainStore().MessagesForBlock(ctx, h)
}
Expand Down
10 changes: 5 additions & 5 deletions chain/state/statetree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func BenchmarkStateTreeSet(b *testing.B) {
func BenchmarkStateTreeSetFlush(b *testing.B) {
//stm: @CHAIN_STATETREE_SET_ACTOR_001
cst := cbor.NewMemCborStore()
sv, err := VersionForNetwork(build.NewestNetworkVersion)
sv, err := VersionForNetwork(build.TestNetworkVersion)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestResolveCache(t *testing.T) {
//stm: @CHAIN_STATETREE_SET_ACTOR_001, @CHAIN_STATETREE_GET_ACTOR_001, @CHAIN_STATETREE_VERSION_FOR_NETWORK_001
//stm: @CHAIN_STATETREE_SNAPSHOT_001, @CHAIN_STATETREE_SNAPSHOT_CLEAR_001
cst := cbor.NewMemCborStore()
sv, err := VersionForNetwork(build.NewestNetworkVersion)
sv, err := VersionForNetwork(build.TestNetworkVersion)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -189,7 +189,7 @@ func BenchmarkStateTree10kGetActor(b *testing.B) {
//stm: @CHAIN_STATETREE_SET_ACTOR_001, @CHAIN_STATETREE_GET_ACTOR_001, @CHAIN_STATETREE_VERSION_FOR_NETWORK_001
//stm: @CHAIN_STATETREE_FLUSH_001
cst := cbor.NewMemCborStore()
sv, err := VersionForNetwork(build.NewestNetworkVersion)
sv, err := VersionForNetwork(build.TestNetworkVersion)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func BenchmarkStateTree10kGetActor(b *testing.B) {
func TestSetCache(t *testing.T) {
//stm: @CHAIN_STATETREE_SET_ACTOR_001, @CHAIN_STATETREE_GET_ACTOR_001, @CHAIN_STATETREE_VERSION_FOR_NETWORK_001
cst := cbor.NewMemCborStore()
sv, err := VersionForNetwork(build.NewestNetworkVersion)
sv, err := VersionForNetwork(build.TestNetworkVersion)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestSnapshots(t *testing.T) {
ctx := context.Background()
cst := cbor.NewMemCborStore()

sv, err := VersionForNetwork(build.NewestNetworkVersion)
sv, err := VersionForNetwork(build.TestNetworkVersion)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func bps(sectorSize abi.SectorSize, sectorNum int, d time.Duration) string {
}

func spt(ssize abi.SectorSize) abi.RegisteredSealProof {
spt, err := miner.SealProofTypeFromSectorSize(ssize, build.NewestNetworkVersion)
spt, err := miner.SealProofTypeFromSectorSize(ssize, build.TestNetworkVersion)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-seed/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ var genesisSetActorVersionCmd = &cli.Command{
}

nv := network.Version(cctx.Int("network-version"))
if nv > build.NewestNetworkVersion {
if nv > build.TestNetworkVersion {
return xerrors.Errorf("invalid network version: %d", nv)
}

Expand Down
2 changes: 1 addition & 1 deletion itests/kit/ensemble_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var DefaultEnsembleOpts = ensembleOpts{
pastOffset: 10000000 * time.Second, // time sufficiently in the past to trigger catch-up mining.
upgradeSchedule: stmgr.UpgradeSchedule{{
Height: -1,
Network: build.NewestNetworkVersion,
Network: build.TestNetworkVersion,
}},
}

Expand Down
2 changes: 1 addition & 1 deletion paychmgr/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,5 @@ func (pchapi *mockPaychAPI) addSigningKey(key []byte) {
}

func (pchapi *mockPaychAPI) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) {
return build.NewestNetworkVersion, nil
return build.TestNetworkVersion, nil
}
2 changes: 1 addition & 1 deletion storage/pipeline/precommit_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func fakeConfigGetter(stub *fakeConfigStub) dtypes.GetSealingConfigFunc {
}

func (f *fakeChain) StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error) {
return build.NewestNetworkVersion, nil
return build.TestNetworkVersion, nil
}

func (f *fakeChain) ChainHead(ctx context.Context) (*types.TipSet, error) {
Expand Down
2 changes: 1 addition & 1 deletion storage/wdpost/wdpost_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, a address.Addr
}

func (m *mockStorageMinerAPI) StateNetworkVersion(ctx context.Context, key types.TipSetKey) (network.Version, error) {
return build.NewestNetworkVersion, nil
return build.TestNetworkVersion, nil
}

func (m *mockStorageMinerAPI) StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) {
Expand Down