Merge remote-tracking branch 'origin/next' into ntwk-calibration
This commit is contained in:
commit
002e972f75
@ -874,9 +874,9 @@ func TestOptimalMessageSelection3(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand) (float64, float64) {
|
func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand, getPremium func() uint64) (float64, float64) {
|
||||||
// in this test we use 100 actors and send 10 blocks of messages.
|
// in this test we use 300 actors and send 10 blocks of messages.
|
||||||
// actors send with an exponentially decreasing premium.
|
// actors send with an randomly distributed premium dictated by the getPremium function.
|
||||||
// a number of miners select with varying ticket quality and we compare the
|
// a number of miners select with varying ticket quality and we compare the
|
||||||
// capacity and rewards of greedy selection -vs- optimal selection
|
// capacity and rewards of greedy selection -vs- optimal selection
|
||||||
|
|
||||||
@ -919,10 +919,10 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand) (float64, flo
|
|||||||
for i := 0; i < nMessages; i++ {
|
for i := 0; i < nMessages; i++ {
|
||||||
from := rng.Intn(nActors)
|
from := rng.Intn(nActors)
|
||||||
to := rng.Intn(nActors)
|
to := rng.Intn(nActors)
|
||||||
premium := 20000*math.Exp(-3.*rand.Float64()) + 5000
|
|
||||||
nonce := nonces[from]
|
nonce := nonces[from]
|
||||||
nonces[from]++
|
nonces[from]++
|
||||||
m := makeTestMessage(wallets[from], actors[from], actors[to], uint64(nonce), gasLimit, uint64(premium))
|
premium := getPremium()
|
||||||
|
m := makeTestMessage(wallets[from], actors[from], actors[to], nonce, gasLimit, premium)
|
||||||
mustAdd(t, mp, m)
|
mustAdd(t, mp, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,12 +1003,44 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand) (float64, flo
|
|||||||
return capacityBoost, rewardBoost
|
return capacityBoost, rewardBoost
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompetitiveMessageSelection(t *testing.T) {
|
func makeExpPremiumDistribution(rng *rand.Rand) func() uint64 {
|
||||||
|
return func() uint64 {
|
||||||
|
premium := 20000*math.Exp(-3.*rng.Float64()) + 5000
|
||||||
|
return uint64(premium)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeZipfPremiumDistribution(rng *rand.Rand) func() uint64 {
|
||||||
|
zipf := rand.NewZipf(rng, 1.001, 1, 40000)
|
||||||
|
return func() uint64 {
|
||||||
|
return zipf.Uint64() + 10000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompetitiveMessageSelectionExp(t *testing.T) {
|
||||||
var capacityBoost, rewardBoost float64
|
var capacityBoost, rewardBoost float64
|
||||||
seeds := []int64{1947, 1976, 2020, 2100, 10000, 143324, 432432, 131, 32, 45}
|
seeds := []int64{1947, 1976, 2020, 2100, 10000, 143324, 432432, 131, 32, 45}
|
||||||
for _, seed := range seeds {
|
for _, seed := range seeds {
|
||||||
t.Log("running competitve message selection with seed", seed)
|
t.Log("running competitive message selection with Exponential premium distribution and seed", seed)
|
||||||
cb, rb := testCompetitiveMessageSelection(t, rand.New(rand.NewSource(seed)))
|
rng := rand.New(rand.NewSource(seed))
|
||||||
|
cb, rb := testCompetitiveMessageSelection(t, rng, makeExpPremiumDistribution(rng))
|
||||||
|
capacityBoost += cb
|
||||||
|
rewardBoost += rb
|
||||||
|
}
|
||||||
|
|
||||||
|
capacityBoost /= float64(len(seeds))
|
||||||
|
rewardBoost /= float64(len(seeds))
|
||||||
|
t.Logf("Average capacity boost across all seeds: %f", capacityBoost)
|
||||||
|
t.Logf("Average reward boost across all seeds: %f", rewardBoost)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompetitiveMessageSelectionZipf(t *testing.T) {
|
||||||
|
var capacityBoost, rewardBoost float64
|
||||||
|
seeds := []int64{1947, 1976, 2020, 2100, 10000, 143324, 432432, 131, 32, 45}
|
||||||
|
for _, seed := range seeds {
|
||||||
|
t.Log("running competitive message selection with Zipf premium distribution and seed", seed)
|
||||||
|
rng := rand.New(rand.NewSource(seed))
|
||||||
|
cb, rb := testCompetitiveMessageSelection(t, rng, makeZipfPremiumDistribution(rng))
|
||||||
capacityBoost += cb
|
capacityBoost += cb
|
||||||
rewardBoost += rb
|
rewardBoost += rb
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
ma "github.com/multiformats/go-multiaddr"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -19,6 +21,7 @@ var actorCmd = &cli.Command{
|
|||||||
Usage: "manipulate the miner actor",
|
Usage: "manipulate the miner actor",
|
||||||
Subcommands: []*cli.Command{
|
Subcommands: []*cli.Command{
|
||||||
actorSetAddrsCmd,
|
actorSetAddrsCmd,
|
||||||
|
actorWithdrawCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,3 +94,75 @@ var actorSetAddrsCmd = &cli.Command{
|
|||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var actorWithdrawCmd = &cli.Command{
|
||||||
|
Name: "withdraw",
|
||||||
|
Usage: "withdraw available balance",
|
||||||
|
ArgsUsage: "[amount (FIL)]",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
|
||||||
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer acloser()
|
||||||
|
|
||||||
|
ctx := lcli.ReqContext(cctx)
|
||||||
|
|
||||||
|
maddr, err := nodeApi.ActorAddress(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
available, err := api.StateMinerAvailableBalance(ctx, maddr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
amount := available
|
||||||
|
if cctx.Args().Present() {
|
||||||
|
f, err := types.ParseFIL(cctx.Args().First())
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("parsing 'amount' argument: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
amount = abi.TokenAmount(f)
|
||||||
|
|
||||||
|
if amount.GreaterThan(available) {
|
||||||
|
return xerrors.Errorf("can't withdraw more funds than available; requested: %s; available: %s", amount, available)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
params, err := actors.SerializeParams(&miner.WithdrawBalanceParams{
|
||||||
|
AmountRequested: amount, // Default to attempting to withdraw all the extra funds in the miner actor
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
smsg, err := api.MpoolPushMessage(ctx, &types.Message{
|
||||||
|
To: maddr,
|
||||||
|
From: mi.Owner,
|
||||||
|
Value: types.NewInt(0),
|
||||||
|
Method: builtin.MethodsMiner.WithdrawBalance,
|
||||||
|
Params: params,
|
||||||
|
}, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Requested rewards withdrawal in message %s\n", smsg.Cid())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -33,7 +33,6 @@ func main() {
|
|||||||
runCmd,
|
runCmd,
|
||||||
stopCmd,
|
stopCmd,
|
||||||
lcli.WithCategory("chain", actorCmd),
|
lcli.WithCategory("chain", actorCmd),
|
||||||
lcli.WithCategory("chain", rewardsCmd),
|
|
||||||
lcli.WithCategory("chain", infoCmd),
|
lcli.WithCategory("chain", infoCmd),
|
||||||
lcli.WithCategory("market", storageDealsCmd),
|
lcli.WithCategory("market", storageDealsCmd),
|
||||||
lcli.WithCategory("market", retrievalDealsCmd),
|
lcli.WithCategory("market", retrievalDealsCmd),
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
|
||||||
)
|
|
||||||
|
|
||||||
var rewardsCmd = &cli.Command{
|
|
||||||
Name: "rewards",
|
|
||||||
Subcommands: []*cli.Command{
|
|
||||||
rewardsRedeemCmd,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var rewardsRedeemCmd = &cli.Command{
|
|
||||||
Name: "redeem",
|
|
||||||
Usage: "Redeem block rewards",
|
|
||||||
Action: func(cctx *cli.Context) error {
|
|
||||||
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer closer()
|
|
||||||
|
|
||||||
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer acloser()
|
|
||||||
|
|
||||||
ctx := lcli.ReqContext(cctx)
|
|
||||||
|
|
||||||
maddr, err := nodeApi.ActorAddress(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
params, err := actors.SerializeParams(&miner.WithdrawBalanceParams{
|
|
||||||
AmountRequested: mact.Balance, // Default to attempting to withdraw all the extra funds in the miner actor
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
smsg, err := api.MpoolPushMessage(ctx, &types.Message{
|
|
||||||
To: maddr,
|
|
||||||
From: mi.Owner,
|
|
||||||
Value: types.NewInt(0),
|
|
||||||
Method: builtin.MethodsMiner.WithdrawBalance,
|
|
||||||
Params: params,
|
|
||||||
}, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Requested rewards withdrawal in message %s\n", smsg.Cid())
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user