Merge pull request #10595 from filecoin-project/asr/backport
Backport #10546, #10553
This commit is contained in:
commit
b40ab4bd44
@ -52,8 +52,8 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
|
// CallWithGas calculates the state for a given tipset, and then applies the given message on top of that state.
|
||||||
func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet) (*api.InvocResult, error) {
|
func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs []types.ChainMsg, ts *types.TipSet, applyTsMessages bool) (*api.InvocResult, error) {
|
||||||
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, true)
|
return sm.callInternal(ctx, msg, priorMsgs, ts, cid.Undef, sm.GetNetworkVersion, true, applyTsMessages)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallAtStateAndVersion allows you to specify a message to execute on the given stateCid and network version.
|
// CallAtStateAndVersion allows you to specify a message to execute on the given stateCid and network version.
|
||||||
@ -117,12 +117,22 @@ func (sm *StateManager) callInternal(ctx context.Context, msg *types.Message, pr
|
|||||||
if stateCid == cid.Undef {
|
if stateCid == cid.Undef {
|
||||||
stateCid = ts.ParentState()
|
stateCid = ts.ParentState()
|
||||||
}
|
}
|
||||||
|
tsMsgs, err := sm.cs.MessagesForTipset(ctx, ts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("failed to lookup messages for parent tipset: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
if applyTsMessages {
|
if applyTsMessages {
|
||||||
tsMsgs, err := sm.cs.MessagesForTipset(ctx, ts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("failed to lookup messages for parent tipset: %w", err)
|
|
||||||
}
|
|
||||||
priorMsgs = append(tsMsgs, priorMsgs...)
|
priorMsgs = append(tsMsgs, priorMsgs...)
|
||||||
|
} else {
|
||||||
|
var filteredTsMsgs []types.ChainMsg
|
||||||
|
for _, tsMsg := range tsMsgs {
|
||||||
|
//TODO we should technically be normalizing the filecoin address of from when we compare here
|
||||||
|
if tsMsg.VMMessage().From == msg.VMMessage().From {
|
||||||
|
filteredTsMsgs = append(filteredTsMsgs, tsMsg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
priorMsgs = append(filteredTsMsgs, priorMsgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Technically, the tipset we're passing in here should be ts+1, but that may not exist.
|
// Technically, the tipset we're passing in here should be ts+1, but that may not exist.
|
||||||
|
@ -340,7 +340,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) {
|
|||||||
currentHeight := ts.TipSet.TipSet().Height()
|
currentHeight := ts.TipSet.TipSet().Height()
|
||||||
|
|
||||||
// CallWithGas calls on top of the given tipset.
|
// CallWithGas calls on top of the given tipset.
|
||||||
ret, err := sm.CallWithGas(ctx, m, nil, ts.TipSet.TipSet())
|
ret, err := sm.CallWithGas(ctx, m, nil, ts.TipSet.TipSet(), true)
|
||||||
if parentHeight <= testForkHeight && currentHeight >= testForkHeight {
|
if parentHeight <= testForkHeight && currentHeight >= testForkHeight {
|
||||||
// If I had a fork, or I _will_ have a fork, it should fail.
|
// If I had a fork, or I _will_ have a fork, it should fail.
|
||||||
require.Equal(t, ErrExpensiveFork, err)
|
require.Equal(t, ErrExpensiveFork, err)
|
||||||
@ -361,7 +361,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) {
|
|||||||
// Calls without a tipset should walk back to the last non-fork tipset.
|
// Calls without a tipset should walk back to the last non-fork tipset.
|
||||||
// We _verify_ that the migration wasn't run multiple times at the end of the
|
// We _verify_ that the migration wasn't run multiple times at the end of the
|
||||||
// test.
|
// test.
|
||||||
ret, err = sm.CallWithGas(ctx, m, nil, nil)
|
ret, err = sm.CallWithGas(ctx, m, nil, nil, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, ret.MsgRct.ExitCode.IsSuccess())
|
require.True(t, ret.MsgRct.ExitCode.IsSuccess())
|
||||||
|
|
||||||
|
@ -130,8 +130,7 @@ type StateManager struct {
|
|||||||
postIgnitionVesting []msig0.State
|
postIgnitionVesting []msig0.State
|
||||||
postCalicoVesting []msig0.State
|
postCalicoVesting []msig0.State
|
||||||
|
|
||||||
genesisPledge abi.TokenAmount
|
genesisPledge abi.TokenAmount
|
||||||
genesisMarketFunds abi.TokenAmount
|
|
||||||
|
|
||||||
tsExec Executor
|
tsExec Executor
|
||||||
tsExecMonitor ExecMonitor
|
tsExecMonitor ExecMonitor
|
||||||
|
@ -51,17 +51,13 @@ func (sm *StateManager) setupGenesisVestingSchedule(ctx context.Context) error {
|
|||||||
return xerrors.Errorf("loading state tree: %w", err)
|
return xerrors.Errorf("loading state tree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
gmf, err := getFilMarketLocked(ctx, sTree)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("setting up genesis market funds: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
gp, err := getFilPowerLocked(ctx, sTree)
|
gp, err := getFilPowerLocked(ctx, sTree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("setting up genesis pledge: %w", err)
|
return xerrors.Errorf("setting up genesis pledge: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.genesisMarketFunds = gmf
|
sm.genesisMsigLk.Lock()
|
||||||
|
defer sm.genesisMsigLk.Unlock()
|
||||||
sm.genesisPledge = gp
|
sm.genesisPledge = gp
|
||||||
|
|
||||||
totalsByEpoch := make(map[abi.ChainEpoch]abi.TokenAmount)
|
totalsByEpoch := make(map[abi.ChainEpoch]abi.TokenAmount)
|
||||||
@ -128,6 +124,8 @@ func (sm *StateManager) setupPostIgnitionVesting(ctx context.Context) error {
|
|||||||
totalsByEpoch[sixYears] = big.NewInt(100_000_000)
|
totalsByEpoch[sixYears] = big.NewInt(100_000_000)
|
||||||
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000))
|
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000))
|
||||||
|
|
||||||
|
sm.genesisMsigLk.Lock()
|
||||||
|
defer sm.genesisMsigLk.Unlock()
|
||||||
sm.postIgnitionVesting = make([]msig0.State, 0, len(totalsByEpoch))
|
sm.postIgnitionVesting = make([]msig0.State, 0, len(totalsByEpoch))
|
||||||
for k, v := range totalsByEpoch {
|
for k, v := range totalsByEpoch {
|
||||||
ns := msig0.State{
|
ns := msig0.State{
|
||||||
@ -178,6 +176,9 @@ func (sm *StateManager) setupPostCalicoVesting(ctx context.Context) error {
|
|||||||
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000))
|
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(300_000_000))
|
||||||
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(9_805_053))
|
totalsByEpoch[sixYears] = big.Add(totalsByEpoch[sixYears], big.NewInt(9_805_053))
|
||||||
|
|
||||||
|
sm.genesisMsigLk.Lock()
|
||||||
|
defer sm.genesisMsigLk.Unlock()
|
||||||
|
|
||||||
sm.postCalicoVesting = make([]msig0.State, 0, len(totalsByEpoch))
|
sm.postCalicoVesting = make([]msig0.State, 0, len(totalsByEpoch))
|
||||||
for k, v := range totalsByEpoch {
|
for k, v := range totalsByEpoch {
|
||||||
ns := msig0.State{
|
ns := msig0.State{
|
||||||
@ -198,21 +199,20 @@ func (sm *StateManager) setupPostCalicoVesting(ctx context.Context) error {
|
|||||||
func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch) (abi.TokenAmount, error) {
|
func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||||
vf := big.Zero()
|
vf := big.Zero()
|
||||||
|
|
||||||
sm.genesisMsigLk.Lock()
|
|
||||||
defer sm.genesisMsigLk.Unlock()
|
|
||||||
|
|
||||||
// TODO: combine all this?
|
// TODO: combine all this?
|
||||||
if sm.preIgnitionVesting == nil || sm.genesisPledge.IsZero() || sm.genesisMarketFunds.IsZero() {
|
if sm.preIgnitionVesting == nil || sm.genesisPledge.IsZero() {
|
||||||
err := sm.setupGenesisVestingSchedule(ctx)
|
err := sm.setupGenesisVestingSchedule(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vf, xerrors.Errorf("failed to setup pre-ignition vesting schedule: %w", err)
|
return vf, xerrors.Errorf("failed to setup pre-ignition vesting schedule: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if sm.postIgnitionVesting == nil {
|
if sm.postIgnitionVesting == nil {
|
||||||
err := sm.setupPostIgnitionVesting(ctx)
|
err := sm.setupPostIgnitionVesting(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vf, xerrors.Errorf("failed to setup post-ignition vesting schedule: %w", err)
|
return vf, xerrors.Errorf("failed to setup post-ignition vesting schedule: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if sm.postCalicoVesting == nil {
|
if sm.postCalicoVesting == nil {
|
||||||
err := sm.setupPostCalicoVesting(ctx)
|
err := sm.setupPostCalicoVesting(ctx)
|
||||||
@ -246,8 +246,6 @@ func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch)
|
|||||||
if height <= build.UpgradeAssemblyHeight {
|
if height <= build.UpgradeAssemblyHeight {
|
||||||
// continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch
|
// continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch
|
||||||
vf = big.Add(vf, sm.genesisPledge)
|
vf = big.Add(vf, sm.genesisPledge)
|
||||||
// continue to use preIgnitionGenInfos, nothing changed at the Ignition epoch
|
|
||||||
vf = big.Add(vf, sm.genesisMarketFunds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return vf, nil
|
return vf, nil
|
||||||
|
@ -240,7 +240,7 @@ var replayOfflineCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
tw := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', tabwriter.AlignRight)
|
tw := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', tabwriter.AlignRight)
|
||||||
res, err := sm.CallWithGas(ctx, msg, []types.ChainMsg{}, executionTs)
|
res, err := sm.CallWithGas(ctx, msg, []types.ChainMsg{}, executionTs, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@ -888,9 +889,14 @@ func (a *EthModule) applyMessage(ctx context.Context, msg *types.Message, tsk ty
|
|||||||
return nil, xerrors.Errorf("cannot get tipset: %w", err)
|
return nil, xerrors.Errorf("cannot get tipset: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyTsMessages := true
|
||||||
|
if os.Getenv("LOTUS_SKIP_APPLY_TS_MESSAGE_CALL_WITH_GAS") == "1" {
|
||||||
|
applyTsMessages = false
|
||||||
|
}
|
||||||
|
|
||||||
// Try calling until we find a height with no migration.
|
// Try calling until we find a height with no migration.
|
||||||
for {
|
for {
|
||||||
res, err = a.StateManager.CallWithGas(ctx, msg, []types.ChainMsg{}, ts)
|
res, err = a.StateManager.CallWithGas(ctx, msg, []types.ChainMsg{}, ts, applyTsMessages)
|
||||||
if err != stmgr.ErrExpensiveFork {
|
if err != stmgr.ErrExpensiveFork {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -959,10 +965,15 @@ func gasSearch(
|
|||||||
high := msg.GasLimit
|
high := msg.GasLimit
|
||||||
low := msg.GasLimit
|
low := msg.GasLimit
|
||||||
|
|
||||||
|
applyTsMessages := true
|
||||||
|
if os.Getenv("LOTUS_SKIP_APPLY_TS_MESSAGE_CALL_WITH_GAS") == "1" {
|
||||||
|
applyTsMessages = false
|
||||||
|
}
|
||||||
|
|
||||||
canSucceed := func(limit int64) (bool, error) {
|
canSucceed := func(limit int64) (bool, error) {
|
||||||
msg.GasLimit = limit
|
msg.GasLimit = limit
|
||||||
|
|
||||||
res, err := smgr.CallWithGas(ctx, &msg, priorMsgs, ts)
|
res, err := smgr.CallWithGas(ctx, &msg, priorMsgs, ts, applyTsMessages)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, xerrors.Errorf("CallWithGas failed: %w", err)
|
return false, xerrors.Errorf("CallWithGas failed: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
lru "github.com/hashicorp/golang-lru/v2"
|
lru "github.com/hashicorp/golang-lru/v2"
|
||||||
@ -276,10 +277,15 @@ func gasEstimateCallWithGas(
|
|||||||
priorMsgs = append(priorMsgs, m)
|
priorMsgs = append(priorMsgs, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applyTsMessages := true
|
||||||
|
if os.Getenv("LOTUS_SKIP_APPLY_TS_MESSAGE_CALL_WITH_GAS") == "1" {
|
||||||
|
applyTsMessages = false
|
||||||
|
}
|
||||||
|
|
||||||
// Try calling until we find a height with no migration.
|
// Try calling until we find a height with no migration.
|
||||||
var res *api.InvocResult
|
var res *api.InvocResult
|
||||||
for {
|
for {
|
||||||
res, err = smgr.CallWithGas(ctx, &msg, priorMsgs, ts)
|
res, err = smgr.CallWithGas(ctx, &msg, priorMsgs, ts, applyTsMessages)
|
||||||
if err != stmgr.ErrExpensiveFork {
|
if err != stmgr.ErrExpensiveFork {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user