add client
This commit is contained in:
parent
e88c2061f1
commit
0addc7207e
@ -7,6 +7,8 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
||||
@ -62,7 +64,7 @@ var fip0036PollResultcmd = &cli.Command{
|
||||
Subcommands: []*cli.Command{
|
||||
//spRBPCmd,
|
||||
//spDealByteCmd,
|
||||
//clientCmd,
|
||||
clientCmd,
|
||||
tokenHolderCmd,
|
||||
//coreDevCmd,
|
||||
//finalResultCmd,
|
||||
@ -191,8 +193,8 @@ var tokenHolderCmd = &cli.Command{
|
||||
//get all the msig
|
||||
msigs, err := getAllMsig(tree, store)
|
||||
|
||||
var acceptanceVote []Vote
|
||||
var rejectionVote []Vote
|
||||
acceptanceVote := 0
|
||||
rejectionVote := 0
|
||||
acceptanceBalance := abi.NewTokenAmount(0)
|
||||
rejectionBalance := abi.NewTokenAmount(0)
|
||||
msigPendingVotes := make(map[address.Address]msigVote)
|
||||
@ -205,10 +207,10 @@ var tokenHolderCmd = &cli.Command{
|
||||
}
|
||||
//regular account
|
||||
if v.OptionID == APPROVE {
|
||||
acceptanceVote = append(acceptanceVote, v)
|
||||
acceptanceVote += 1
|
||||
acceptanceBalance = types.BigAdd(acceptanceBalance, a.Balance)
|
||||
} else {
|
||||
rejectionVote = append(rejectionVote, v)
|
||||
rejectionVote += 1
|
||||
rejectionBalance = types.BigAdd(rejectionBalance, a.Balance)
|
||||
}
|
||||
|
||||
@ -218,7 +220,6 @@ var tokenHolderCmd = &cli.Command{
|
||||
return xerrors.Errorf("cannot resolve singer: ", si)
|
||||
}
|
||||
for _, m := range msigs {
|
||||
|
||||
for _, ms := range m.Signer {
|
||||
if ms == si {
|
||||
if mv, found := msigPendingVotes[m.ID]; found { //other singer has voted
|
||||
@ -270,11 +271,13 @@ var tokenHolderCmd = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("\nTotoal amount of singers: %v\n ", len(votes))
|
||||
fmt.Printf("Totoal amount of valid multisig vote: %v\n ", len(msigFinalVotes))
|
||||
fmt.Printf("\nTotal amount of singers: %v\n ", len(votes))
|
||||
fmt.Printf("Total amount of valid multisig vote: %v\n ", len(msigFinalVotes))
|
||||
fmt.Printf("Total balance: %v\n", types.BigAdd(acceptanceBalance, rejectionBalance).String())
|
||||
fmt.Printf("Approve: %v\n", acceptanceBalance.String())
|
||||
fmt.Printf("Reject: %v\n", rejectionBalance.String())
|
||||
fmt.Printf("Approve (#): %v\n", acceptanceVote)
|
||||
fmt.Printf("Reject (#): %v\n", rejectionVote)
|
||||
fmt.Printf("Approve (FIL): %v\n", acceptanceBalance.String())
|
||||
fmt.Printf("Reject (FIL): %v\n", rejectionBalance.String())
|
||||
av := types.BigDivFloat(acceptanceBalance, types.BigAdd(acceptanceBalance, rejectionBalance))
|
||||
rv := types.BigDivFloat(rejectionBalance, types.BigAdd(rejectionBalance, acceptanceBalance))
|
||||
if av > 0.05 {
|
||||
@ -285,3 +288,136 @@ var tokenHolderCmd = &cli.Command{
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
var clientCmd = &cli.Command{
|
||||
Name: "client",
|
||||
Usage: "get poll result for client",
|
||||
ArgsUsage: "[state root]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "repo",
|
||||
Value: "~/.lotus",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
if cctx.NArg() != 2 {
|
||||
return xerrors.New("filpoll0036 token-holder [state root] [votes.json]")
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
if !cctx.Args().Present() {
|
||||
return fmt.Errorf("must pass state root")
|
||||
}
|
||||
|
||||
sroot, err := cid.Decode(cctx.Args().First())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse input: %w", err)
|
||||
}
|
||||
|
||||
fsrepo, err := repo.NewFS(cctx.String("repo"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lkrepo, err := fsrepo.Lock(repo.FullNode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer lkrepo.Close() //nolint:errcheck
|
||||
|
||||
bs, err := lkrepo.Blockstore(ctx, repo.UniversalBlockstore)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open blockstore: %w", err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if c, ok := bs.(io.Closer); ok {
|
||||
if err := c.Close(); err != nil {
|
||||
log.Warnf("failed to close blockstore: %s", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
mds, err := lkrepo.Datastore(context.Background(), "/metadata")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cs := store.NewChainStore(bs, bs, mds, filcns.Weight, nil)
|
||||
defer cs.Close() //nolint:errcheck
|
||||
|
||||
cst := cbor.NewCborStore(bs)
|
||||
store := adt.WrapStore(ctx, cst)
|
||||
|
||||
tree, err := state.LoadStateTree(cst, sroot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//get all the votes' singer address && their vote
|
||||
vj, err := homedir.Expand(cctx.Args().Get(1))
|
||||
if err != nil {
|
||||
return xerrors.Errorf("fail to get votes json")
|
||||
}
|
||||
votes, err := getVoters(vj)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("fail to get votesrs: ", err)
|
||||
}
|
||||
|
||||
//market actor
|
||||
ma, err := tree.GetActor(market.Address)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("fail to get market actor: ", err)
|
||||
}
|
||||
|
||||
ms, err := market.Load(store, ma)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("fail to load market actor: ", err)
|
||||
}
|
||||
|
||||
dps, _ := ms.Proposals()
|
||||
acceptanceBytes := abi.PaddedPieceSize(0)
|
||||
rejectionBytes := abi.PaddedPieceSize(0)
|
||||
acceptanceCount := 0
|
||||
rejectionCount := 0
|
||||
for _, v := range votes {
|
||||
if err != nil {
|
||||
return xerrors.Errorf("fail to get account account for signer: ", v.SignerAddress)
|
||||
}
|
||||
ai, err := tree.LookupID(v.SignerAddress)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("cannot resolve singer: ", ai)
|
||||
}
|
||||
if err := dps.ForEach(func(dealID abi.DealID, d market.DealProposal) error {
|
||||
p, found, _ := dps.Get(dealID)
|
||||
if found && p.Client == ai {
|
||||
if v.OptionID == APPROVE {
|
||||
acceptanceBytes += p.PieceSize
|
||||
acceptanceCount += 1
|
||||
} else {
|
||||
rejectionBytes += p.PieceSize
|
||||
rejectionCount += 1
|
||||
}
|
||||
}
|
||||
return xerrors.Errorf("cant get deal ", err)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fmt.Printf("\nTotal amount of clients: %v\n", acceptanceCount+rejectionCount)
|
||||
fmt.Printf("Total deal bytes: %v\n", acceptanceBytes+rejectionBytes)
|
||||
fmt.Printf("Approve (#): %v\n", acceptanceCount)
|
||||
fmt.Printf("Reject (#): %v\n", rejectionCount)
|
||||
fmt.Printf("Approve (byte): %v\n", acceptanceBytes)
|
||||
fmt.Printf("Reject (byte): %v\n", rejectionBytes)
|
||||
av := float64(acceptanceBytes) / float64(acceptanceBytes+rejectionBytes)
|
||||
rv := float64(rejectionBytes) / float64(acceptanceBytes+rejectionBytes)
|
||||
if av > 0.05 {
|
||||
fmt.Printf("Deal Client Group Result: Pass. approve: %.5f, reject: %.5f\n", av, rv)
|
||||
} else {
|
||||
fmt.Printf("Deal Client Group Result: Not Pass. approve: %.5f, reject: %.5f\n", av, rv)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user