Implement FIP-0015
This commit is contained in:
parent
2b93bcde72
commit
7fca1c1ee7
@ -6,6 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -846,3 +848,155 @@ waitForProof:
|
|||||||
require.Contains(t, err.Error(), "failed to dispute valid post (RetCode=16)")
|
require.Contains(t, err.Error(), "failed to dispute valid post (RetCode=16)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWindowPostBaseFeeNoBurn(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
och := build.UpgradeClausHeight
|
||||||
|
build.UpgradeClausHeight = 10
|
||||||
|
n, sn := b(t, DefaultFullOpts(1), OneMiner)
|
||||||
|
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
{
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maddr, err := miner.ActorAddress(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for ctx.Err() == nil {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
// context was canceled, ignore the error.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
cancel()
|
||||||
|
<-done
|
||||||
|
}()
|
||||||
|
|
||||||
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
en := wact.Nonce
|
||||||
|
|
||||||
|
// wait for a new message to be sent from worker address, it will be a PoSt
|
||||||
|
|
||||||
|
waitForProof:
|
||||||
|
for {
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if wact.Nonce > en {
|
||||||
|
break waitForProof
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
}
|
||||||
|
|
||||||
|
slm, err := client.StateListMessages(ctx, &api.MessageMatch{To: maddr}, types.EmptyTSK, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pmr, err := client.StateReplay(ctx, types.EmptyTSK, slm[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, pmr.GasCost.BaseFeeBurn, big.Zero())
|
||||||
|
|
||||||
|
build.UpgradeClausHeight = och
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWindowPostBaseFeeBurn(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, OneMiner)
|
||||||
|
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
{
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maddr, err := miner.ActorAddress(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for ctx.Err() == nil {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
// context was canceled, ignore the error.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
cancel()
|
||||||
|
<-done
|
||||||
|
}()
|
||||||
|
|
||||||
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
en := wact.Nonce
|
||||||
|
|
||||||
|
// wait for a new message to be sent from worker address, it will be a PoSt
|
||||||
|
|
||||||
|
waitForProof:
|
||||||
|
for {
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if wact.Nonce > en {
|
||||||
|
break waitForProof
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
}
|
||||||
|
|
||||||
|
slm, err := client.StateListMessages(ctx, &api.MessageMatch{To: maddr}, types.EmptyTSK, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pmr, err := client.StateReplay(ctx, types.EmptyTSK, slm[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NotEqual(t, pmr.GasCost.BaseFeeBurn, big.Zero())
|
||||||
|
}
|
||||||
|
@ -51,7 +51,7 @@ const UpgradePersianHeight = UpgradeCalicoHeight + (builtin2.EpochsInHour * 60)
|
|||||||
const UpgradeOrangeHeight = 336458
|
const UpgradeOrangeHeight = 336458
|
||||||
|
|
||||||
// 2020-12-22T02:00:00Z
|
// 2020-12-22T02:00:00Z
|
||||||
const UpgradeClausHeight = 343200
|
var UpgradeClausHeight = abi.ChainEpoch(343200)
|
||||||
|
|
||||||
// 2021-03-04T00:00:30Z
|
// 2021-03-04T00:00:30Z
|
||||||
const UpgradeTrustHeight = 550321
|
const UpgradeTrustHeight = 550321
|
||||||
|
@ -566,7 +566,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
|
|||||||
gasUsed = 0
|
gasUsed = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
burn, err := vm.ShouldBurn(st, msg, errcode)
|
burn, err := vm.ShouldBurn(ctx, st, msg, errcode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("deciding whether should burn failed: %w", err)
|
return nil, xerrors.Errorf("deciding whether should burn failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -609,7 +609,8 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vm *VM) ShouldBurn(st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) {
|
func (vm *VM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) {
|
||||||
|
if vm.ntwkVersion(ctx, vm.blockHeight) <= network.Version12 {
|
||||||
// Check to see if we should burn funds. We avoid burning on successful
|
// Check to see if we should burn funds. We avoid burning on successful
|
||||||
// window post. This won't catch _indirect_ window post calls, but this
|
// window post. This won't catch _indirect_ window post calls, but this
|
||||||
// is the best we can get for now.
|
// is the best we can get for now.
|
||||||
@ -632,6 +633,10 @@ func (vm *VM) ShouldBurn(st *state.StateTree, msg *types.Message, errcode exitco
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Any "don't burn" rules from Network v13 onwards go here, for now we always return true
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (vm *VM) ActorBalance(addr address.Address) (types.BigInt, aerrors.ActorError) {
|
func (vm *VM) ActorBalance(addr address.Address) (types.BigInt, aerrors.ActorError) {
|
||||||
act, err := vm.cstate.GetActor(addr)
|
act, err := vm.cstate.GetActor(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -245,6 +245,34 @@ func TestWindowPostDisputeFails(t *testing.T) {
|
|||||||
test.TestWindowPostDisputeFails(t, builder.MockSbBuilder, 2*time.Millisecond)
|
test.TestWindowPostDisputeFails(t, builder.MockSbBuilder, 2*time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWindowPostBaseFeeNoBurn(t *testing.T) {
|
||||||
|
if os.Getenv("LOTUS_TEST_WINDOW_POST") != "1" {
|
||||||
|
t.Skip("this takes a few minutes, set LOTUS_TEST_WINDOW_POST=1 to run")
|
||||||
|
}
|
||||||
|
logging.SetLogLevel("miner", "ERROR")
|
||||||
|
logging.SetLogLevel("gen", "ERROR")
|
||||||
|
logging.SetLogLevel("chainstore", "ERROR")
|
||||||
|
logging.SetLogLevel("chain", "ERROR")
|
||||||
|
logging.SetLogLevel("sub", "ERROR")
|
||||||
|
logging.SetLogLevel("storageminer", "ERROR")
|
||||||
|
|
||||||
|
test.TestWindowPostBaseFeeNoBurn(t, builder.MockSbBuilder, 2*time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWindowPostBaseFeeBurn(t *testing.T) {
|
||||||
|
if os.Getenv("LOTUS_TEST_WINDOW_POST") != "1" {
|
||||||
|
t.Skip("this takes a few minutes, set LOTUS_TEST_WINDOW_POST=1 to run")
|
||||||
|
}
|
||||||
|
logging.SetLogLevel("miner", "ERROR")
|
||||||
|
logging.SetLogLevel("gen", "ERROR")
|
||||||
|
logging.SetLogLevel("chainstore", "ERROR")
|
||||||
|
logging.SetLogLevel("chain", "ERROR")
|
||||||
|
logging.SetLogLevel("sub", "ERROR")
|
||||||
|
logging.SetLogLevel("storageminer", "ERROR")
|
||||||
|
|
||||||
|
test.TestWindowPostBaseFeeBurn(t, builder.MockSbBuilder, 2*time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDeadlineToggling(t *testing.T) {
|
func TestDeadlineToggling(t *testing.T) {
|
||||||
if os.Getenv("LOTUS_TEST_DEADLINE_TOGGLING") != "1" {
|
if os.Getenv("LOTUS_TEST_DEADLINE_TOGGLING") != "1" {
|
||||||
t.Skip("this takes a few minutes, set LOTUS_TEST_DEADLINE_TOGGLING=1 to run")
|
t.Skip("this takes a few minutes, set LOTUS_TEST_DEADLINE_TOGGLING=1 to run")
|
||||||
|
Loading…
Reference in New Issue
Block a user