generate an account
This commit is contained in:
parent
a62edd05de
commit
3cc3c9a34e
@ -130,7 +130,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
|
|
||||||
// Create init actor
|
// Create init actor
|
||||||
|
|
||||||
initact, err := SetupInitActor(bs, template.NetworkName, template.Accounts)
|
initact, err := SetupInitActor(bs, template.NetworkName, template.Accounts, template.VerifregRootKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("setup init actor: %w", err)
|
return nil, xerrors.Errorf("setup init actor: %w", err)
|
||||||
}
|
}
|
||||||
@ -206,33 +206,9 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// var newAddress address.Address
|
if err = createAccount(ctx, bs, cst, state, ida, info); err != nil {
|
||||||
if (info.Type == genesis.TAccount) {
|
|
||||||
var ainfo genesis.AccountMeta
|
|
||||||
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
|
||||||
return nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
|
||||||
}
|
|
||||||
st, err := cst.Put(ctx, &account.State{Address: ainfo.Owner})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = state.SetActor(ida, &types.Actor{
|
|
||||||
Code: builtin.AccountActorCodeID,
|
|
||||||
Balance: info.Balance,
|
|
||||||
Head: st,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("setting account from actmap: %w", err)
|
|
||||||
}
|
|
||||||
} else if (info.Type == genesis.TMultisig) {
|
|
||||||
var ainfo genesis.MultisigMeta
|
|
||||||
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
|
||||||
return nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
|
||||||
}
|
|
||||||
if err = createMultisig(ctx, bs, cst, state, ida, info.Balance, ainfo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,15 +217,37 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = createMultisig(ctx, bs, cst, state, vregroot, types.NewInt(0), template.VerifregRootKey); err != nil {
|
if err = createAccount(ctx, bs, cst, state, vregroot, template.VerifregRootKey); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createMultisig(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, balance abi.TokenAmount, ainfo genesis.MultisigMeta) error {
|
func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor) error {
|
||||||
|
// var newAddress address.Address
|
||||||
|
if (info.Type == genesis.TAccount) {
|
||||||
|
var ainfo genesis.AccountMeta
|
||||||
|
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
||||||
|
return xerrors.Errorf("unmarshaling account meta: %w", err)
|
||||||
|
}
|
||||||
|
st, err := cst.Put(ctx, &account.State{Address: ainfo.Owner})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = state.SetActor(ida, &types.Actor{
|
||||||
|
Code: builtin.AccountActorCodeID,
|
||||||
|
Balance: info.Balance,
|
||||||
|
Head: st,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("setting account from actmap: %w", err)
|
||||||
|
}
|
||||||
|
} else if (info.Type == genesis.TMultisig) {
|
||||||
|
var ainfo genesis.MultisigMeta
|
||||||
|
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
||||||
|
return xerrors.Errorf("unmarshaling account meta: %w", err)
|
||||||
|
}
|
||||||
pending, err := adt.MakeEmptyMap(adt.WrapStore(ctx, cst)).Root()
|
pending, err := adt.MakeEmptyMap(adt.WrapStore(ctx, cst)).Root()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to create empty map: %v", err)
|
return xerrors.Errorf("failed to create empty map: %v", err)
|
||||||
@ -261,19 +259,21 @@ func createMultisig(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStor
|
|||||||
StartEpoch: abi.ChainEpoch(ainfo.VestingStart),
|
StartEpoch: abi.ChainEpoch(ainfo.VestingStart),
|
||||||
UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration),
|
UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration),
|
||||||
PendingTxns: pending,
|
PendingTxns: pending,
|
||||||
InitialBalance: balance,
|
InitialBalance: info.Balance,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = state.SetActor(ida, &types.Actor{
|
err = state.SetActor(ida, &types.Actor{
|
||||||
Code: builtin.MultisigActorCodeID,
|
Code: builtin.MultisigActorCodeID,
|
||||||
Balance: balance,
|
Balance: info.Balance,
|
||||||
Head: st,
|
Head: st,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("setting account from actmap: %w", err)
|
return xerrors.Errorf("setting account from actmap: %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,13 +298,13 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci
|
|||||||
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = doExecValue(ctx, vm, builtin.VerifiedRegistryActorAddr, RootVerifierAddr, types.NewInt(0), builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg.AddVerifierParams{
|
_, err = doExecValue(ctx, vm, builtin.VerifiedRegistryActorAddr, verifier, types.NewInt(0), builtin.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg.AddVerifierParams{
|
||||||
Address: verifier,
|
Address: verifier,
|
||||||
Allowance: abi.NewStoragePower(int64(sum)), // eh, close enough
|
Allowance: abi.NewStoragePower(int64(sum)), // eh, close enough
|
||||||
|
|
||||||
}))
|
}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("failed to failed to create verifier: %w", err)
|
return cid.Undef, xerrors.Errorf("failed to create verifier: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for c, amt := range verifNeeds {
|
for c, amt := range verifNeeds {
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/genesis"
|
"github.com/filecoin-project/lotus/genesis"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor) (*types.Actor, error) {
|
func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor) (*types.Actor, error) {
|
||||||
if len(initialActors) > MaxAccounts {
|
if len(initialActors) > MaxAccounts {
|
||||||
return nil, xerrors.New("too many initial actors")
|
return nil, xerrors.New("too many initial actors")
|
||||||
}
|
}
|
||||||
@ -50,9 +50,15 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := amap.Set(context.TODO(), string(RootVerifierAddr.Bytes()), 80); err != nil {
|
if rootVerifier.Type == genesis.TAccount {
|
||||||
|
var ainfo genesis.AccountMeta
|
||||||
|
if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil {
|
||||||
|
return nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
||||||
|
}
|
||||||
|
if err := amap.Set(context.TODO(), string(ainfo.Owner.Bytes()), 80); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := amap.Flush(context.TODO()); err != nil {
|
if err := amap.Flush(context.TODO()); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -14,17 +14,9 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RootVerifierAddr address.Address
|
|
||||||
|
|
||||||
var RootVerifierID address.Address
|
var RootVerifierID address.Address
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
k, err := address.NewFromString("t3qfoulel6fy6gn3hjmbhpdpf6fs5aqjb5fkurhtwvgssizq4jey5nw4ptq5up6h7jk7frdvvobv52qzmgjinq")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
RootVerifierAddr = k
|
|
||||||
|
|
||||||
idk, err := address.NewFromString("t080")
|
idk, err := address.NewFromString("t080")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -79,5 +79,5 @@ type Template struct {
|
|||||||
NetworkName string
|
NetworkName string
|
||||||
Timestamp uint64 `json:",omitempty"`
|
Timestamp uint64 `json:",omitempty"`
|
||||||
|
|
||||||
VerifregRootKey MultisigMeta
|
VerifregRootKey Actor
|
||||||
}
|
}
|
||||||
|
74
scripts/balances.sh
Executable file
74
scripts/balances.sh
Executable file
@ -0,0 +1,74 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sleep 20
|
||||||
|
|
||||||
|
lotus wait-api
|
||||||
|
|
||||||
|
lotus chain head
|
||||||
|
|
||||||
|
export MAIN=$(cat ../localnet2.json | jq -r '.Accounts | .[0] | .Meta .Owner')
|
||||||
|
|
||||||
|
# Send funds to root key
|
||||||
|
lotus send --from $MAIN $ROOT 5000000
|
||||||
|
|
||||||
|
export VERIFIER=$(lotus wallet new)
|
||||||
|
export CLIENT=$(lotus wallet new)
|
||||||
|
|
||||||
|
# Send funds to verifier
|
||||||
|
lotus send --from $MAIN $VERIFIER 5000000
|
||||||
|
|
||||||
|
# Send funds to client
|
||||||
|
lotus send --from $MAIN $CLIENT 5000000
|
||||||
|
|
||||||
|
while [ "5000000 FIL" != "$(lotus wallet balance $VERIFIER)" ]
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
lotus wallet balance $ROOT
|
||||||
|
done
|
||||||
|
|
||||||
|
# export PARAM=$(lotus-shed verifreg add-verifier --dry t01001 100000000000000000000000000000000000000000)
|
||||||
|
export PARAM=824300e907440076adf1
|
||||||
|
|
||||||
|
# Add verifier
|
||||||
|
# lotus-shed verifreg add-verifier --from $ROOT t01001 100000000000000000000000000000000000000000
|
||||||
|
|
||||||
|
lotus msig propose --from $MAIN t080 t06 0 2 $PARAM
|
||||||
|
lotus msig inspect t080
|
||||||
|
|
||||||
|
lotus-shed verifreg list-verifiers
|
||||||
|
|
||||||
|
# Add verified client
|
||||||
|
lotus-shed verifreg verify-client --from $VERIFIER $CLIENT 10000
|
||||||
|
lotus-shed verifreg list-clients
|
||||||
|
|
||||||
|
# Remove verifier datacap
|
||||||
|
lotus-shed verifreg add-verifier --from $ROOT t01001 0
|
||||||
|
lotus-shed verifreg list-verifiers
|
||||||
|
|
||||||
|
export DATA=$(lotus client import dddd | awk '{print $NF}')
|
||||||
|
|
||||||
|
lotus client local
|
||||||
|
|
||||||
|
# Client can make a verified deal
|
||||||
|
lotus client deal --verified-deal --from $CLIENT $DATA t01000 0.005 100000
|
||||||
|
|
||||||
|
while [ "3" != "$(lotus-miner sectors list | wc -l)" ]
|
||||||
|
do
|
||||||
|
sleep 10
|
||||||
|
lotus-miner sectors list
|
||||||
|
done
|
||||||
|
|
||||||
|
curl -H "Content-Type: application/json" -H "Authorization: Bearer $(cat ~/.lotusminer/token)" -d '{"id": 1, "method": "Filecoin.SectorStartSealing", "params": [2]}' localhost:2345/rpc/v0
|
||||||
|
|
||||||
|
lotus-miner info
|
||||||
|
|
||||||
|
lotus-miner sectors list
|
||||||
|
|
||||||
|
while [ "3" != "$(lotus-miner sectors list | grep Proving | wc -l)" ]
|
||||||
|
do
|
||||||
|
sleep 5
|
||||||
|
lotus-miner sectors list | tail -n 1
|
||||||
|
lotus-miner info | grep "Actual Power"
|
||||||
|
done
|
||||||
|
|
||||||
|
sleep 300000
|
108
scripts/start-devnet.bash
Executable file
108
scripts/start-devnet.bash
Executable file
@ -0,0 +1,108 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
|
||||||
|
__PWD=$PWD
|
||||||
|
__DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
|
__PARENT_DIR=$(dirname $__DIR)
|
||||||
|
LOTUS_PATH="${1:-$__PARENT_DIR}"
|
||||||
|
LOTUS_PURGE_LOCALDIR=${LOTUS_PURGE_LOCALDIR:-false}
|
||||||
|
LOTUS_COMPILE=${LOTUS_COMPILE:-false}
|
||||||
|
|
||||||
|
|
||||||
|
LOTUS_BIN="$LOTUS_PATH/lotus"
|
||||||
|
LOTUS_SEED="$LOTUS_PATH/lotus-seed"
|
||||||
|
LOTUS_MINER="$LOTUS_PATH/lotus-miner"
|
||||||
|
|
||||||
|
|
||||||
|
##### Functions
|
||||||
|
|
||||||
|
configure_lotus() {
|
||||||
|
|
||||||
|
echo -e "\nDownloading the 2048 byte parameters:\n"
|
||||||
|
$LOTUS_BIN fetch-params 2048
|
||||||
|
|
||||||
|
echo -e "\nPre-seal some sectors:\n"
|
||||||
|
$LOTUS_SEED pre-seal --sector-size 2KiB --num-sectors 2
|
||||||
|
# $LOTUS_SEED pre-seal --sector-size 2KiB --num-sectors 2 --miner-addr t01001
|
||||||
|
|
||||||
|
# export ROOT=$(cat ~/.genesis-sectors/pre-seal-t01001.json | jq -r '.t01001 | .Owner')
|
||||||
|
export MINER=$(cat ~/.genesis-sectors/pre-seal-t01000.json | jq -r '.t01000 | .Owner')
|
||||||
|
|
||||||
|
echo -e "\nCreate the genesis block and start up the first node:\n"
|
||||||
|
$LOTUS_SEED genesis new $LOTUS_PATH/localnet.json
|
||||||
|
$LOTUS_SEED genesis add-miner $LOTUS_PATH/localnet.json ~/.genesis-sectors/pre-seal-t01000.json
|
||||||
|
# $LOTUS_SEED genesis add-msigs $LOTUS_PATH/localnet.json test.csv
|
||||||
|
jq --arg root $MINER '. + {VerifregRootKey: {Meta: {Signers: [$root], Threshold: 1 }, Type: "multisig", Balance: "50000000000000000000000000"}}' ../localnet.json > $LOTUS_PATH/localnet2.json
|
||||||
|
# cp $LOTUS_PATH/localnet.json $LOTUS_PATH/localnet2.json
|
||||||
|
# jq --arg root $ROOT '. + {RootKey: $root}' ../localnet.json > $LOTUS_PATH/localnet2.json
|
||||||
|
# jq --arg root $MINER '.Accounts |= . + [{Type: "multisig", Balance: "50000000000000000000000000", Meta: { Signers: [$root], Threshold: 1 }}]' ../localnet.json > $LOTUS_PATH/localnet2.json
|
||||||
|
|
||||||
|
tmux new-session -s lotus -n script -d bash balances.sh
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
tmux new-window -t lotus:1 -n daemon -d $LOTUS_BIN daemon --lotus-make-genesis=dev.gen --genesis-template=$LOTUS_PATH/localnet2.json --bootstrap=false
|
||||||
|
# $LOTUS_BIN daemon --lotus-make-genesis=dev.gen --genesis-template=$LOTUS_PATH/localnet2.json --bootstrap=false || exit
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
echo -e "\nImporting the genesis miner key:\n"
|
||||||
|
$LOTUS_BIN wallet import ~/.genesis-sectors/pre-seal-t01000.key
|
||||||
|
# $LOTUS_BIN wallet import ~/.genesis-sectors/pre-seal-t01001.key
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
echo -e "\nSetting up the genesis miner:\n"
|
||||||
|
$LOTUS_MINER init --genesis-miner --actor=t01000 --sector-size=2KiB \
|
||||||
|
--pre-sealed-sectors=~/.genesis-sectors \
|
||||||
|
--pre-sealed-metadata=~/.genesis-sectors/pre-seal-t01000.json --nosync
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
echo -e "\nStarting up the miner:\n"
|
||||||
|
tmux new-window -t lotus:2 -n miner -d $LOTUS_MINER run --nosync
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
purge_local_dirs() {
|
||||||
|
echo -e "\nRemoving local state\n"
|
||||||
|
rm -rf ~/.lotus || true
|
||||||
|
rm -rf ~/.lotusstorage || true
|
||||||
|
rm -rf ~/.lotusminer || true
|
||||||
|
rm -rf ~/.genesis-sectors || true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
compile_lotus() {
|
||||||
|
echo -e "\nCompiling lotus binary for devnet usage\n"
|
||||||
|
make clean && make 2k all
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
|
||||||
|
echo -e "\nUsing Lotus Path: $LOTUS_PATH \n"
|
||||||
|
|
||||||
|
if [[ "$LOTUS_PURGE_LOCALDIR" = true ]]; then
|
||||||
|
echo -e "Purging"
|
||||||
|
purge_local_dirs
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ "$LOTUS_COMPILE" = true ]]; then
|
||||||
|
compile_lotus
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
if [[ ! -f $LOTUS_BIN ]]; then
|
||||||
|
echo -e "Lotus binary doesn't exist"
|
||||||
|
echo -e "Please visit https://docs.lotu.sh/en+getting-started for compiling Lotus"
|
||||||
|
echo -e "Please remember to compile lotus with the 2k flag:"
|
||||||
|
echo -e "make 2k"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
configure_lotus
|
||||||
|
}
|
||||||
|
|
||||||
|
#### Main
|
||||||
|
|
||||||
|
main
|
Loading…
Reference in New Issue
Block a user