Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add persistent key mode #49

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
# Changelog

## v0.5.1

* update ffi

## v0.5.0

* Feat/recorver docker cli by @LinZexiao in https://github.com/ipfs-force-community/chain-co/pull/32
* bump uo version to v0.5.0
* update lotus version to v1.22.0
* update venus-auth version to v1.11.0
## v0.5.0-rc1

* Feat: recorver docker ci by @LinZexiao in https://github.com/ipfs-force-community/chain-co/pull/32
* fix: fix wrap rate litmit by @simlecode in https://github.com/ipfs-force-community/chain-co/pull/33
* feat: add status api to detect api ready by @hunjixin in https://github.com/ipfs-force-community/chain-co/pull/34
* fix: build deps before build docker by @LinZexiao in https://github.com/ipfs-force-community/chain-co/pull/36
* Feat/prevent launch without token by @LinZexiao in https://github.com/ipfs-force-community/chain-co/pull/41
* Feat/add docker push by @hunjixin in https://github.com/ipfs-force-community/chain-co/pull/42
* fix/block-not-found by @simlecode in https://github.com/ipfs-force-community/chain-co/pull/45
* Feat: prevent launch without token by @LinZexiao in https://github.com/ipfs-force-community/chain-co/pull/41
* Feat: add docker push by @hunjixin in https://github.com/ipfs-force-community/chain-co/pull/42
* fix: block-not-found by @simlecode in https://github.com/ipfs-force-community/chain-co/pull/45
* chore: support MpoolBatchPushUntrusted by @simlecode in https://github.com/ipfs-force-community/chain-co/pull/37

## v0.4.0
Expand Down
5 changes: 3 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ type Proxy interface {

MpoolPublishByAddr(context.Context, address.Address) error //perm:write

// MpoolGetConfig returns (a copy of) the current mpool config
MpoolGetConfig(context.Context) (*types.MpoolConfig, error) //perm:read

// StateGetRandomnessFromTickets is used to sample the chain for randomness.
StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read
// StateGetRandomnessFromBeacon is used to sample the beacon for randomness.
Expand Down Expand Up @@ -600,8 +603,6 @@ type UnSupport interface {
// MpoolClear clears pending messages from the mpool
MpoolClear(context.Context, bool) error //perm:write

// MpoolGetConfig returns (a copy of) the current mpool config
MpoolGetConfig(context.Context) (*types.MpoolConfig, error) //perm:read
// MpoolSetConfig sets the mpool config to (a copy of) the supplied config
MpoolSetConfig(context.Context, *types.MpoolConfig) error //perm:admin

Expand Down
51 changes: 50 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package main

import (
"context"
"crypto/rand"
"errors"
"io"
"os"
"strings"

Expand Down Expand Up @@ -65,7 +68,12 @@ var runCmd = &cli.Command{
var full v1api.FullNode
var localApi local_api.LocalAPI

localJwt, token, err := jwtclient.NewLocalAuthClient()
//localJwt, token, err := jwtclient.NewLocalAuthClient()
secret, err := getOrGenKey(cctx.Bool("persistent-key-mode"))
if err != nil {
return err
}
localJwt, token, err := jwtclient.NewLocalAuthClientWithSecret(secret)
if err != nil {
return err
}
Expand Down Expand Up @@ -118,3 +126,44 @@ var runCmd = &cli.Command{
)
},
}

// fileExists checks whether the file exists.
func fileExists(filename string) bool {
_, err := os.Stat(filename)
return !errors.Is(err, os.ErrNotExist)
}

func randSecret() ([]byte, error) {
return io.ReadAll(io.LimitReader(rand.Reader, 32))
}
func getOrGenKey(persistentMode bool) ([]byte, error) {
if persistentMode {
keyFile := "./key"
if exist := fileExists(keyFile); exist {
secretRead, err := os.ReadFile(keyFile)
if err != nil {
return nil, err
}
if len(secretRead) == 0 {
return nil, errors.New("key is empty")
}
return secretRead, nil
} else {
secret, err := randSecret()
if err != nil {
return nil, err
}
err = os.WriteFile(keyFile, secret, 0o666)
if err != nil {
return nil, err
}
return secret, nil
}
} else {
secret, err := randSecret()
if err != nil {
return nil, err
}
return secret, nil
}
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (
github.com/filecoin-project/go-data-transfer v1.15.2
github.com/filecoin-project/go-fil-markets v1.25.2
github.com/filecoin-project/go-jsonrpc v0.2.1
github.com/filecoin-project/go-state-types v0.11.0-rc2
github.com/filecoin-project/lotus v1.20.0
github.com/filecoin-project/venus-auth v1.11.0-rc1
github.com/filecoin-project/go-state-types v0.11.1
github.com/filecoin-project/lotus v1.22.0
github.com/filecoin-project/venus-auth v1.11.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/hashicorp/go-multierror v1.1.1
Expand Down Expand Up @@ -238,4 +238,4 @@ replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi

replace github.com/filecoin-project/go-jsonrpc => github.com/ipfs-force-community/go-jsonrpc v0.1.7

replace github.com/filecoin-project/lotus => github.com/ipfs-force-community/lotus v0.8.1-0.20230418033744-8d4f6744d906
replace github.com/filecoin-project/lotus => github.com/ipfs-force-community/lotus v0.8.1-0.20230423011510-75338a5bf2e1
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ github.com/filecoin-project/go-state-types v0.0.0-20210119062722-4adba5aaea71/go
github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g=
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.11.0-rc1/go.mod h1:SyNPwTsU7I22gL2r0OAPcImvLoTVfgRwdK/Y5rR1zz8=
github.com/filecoin-project/go-state-types v0.11.0-rc2 h1:zUx7aRxEGn56n4A1RS2J8FZzpzAozEMsqF11aXjtmkc=
github.com/filecoin-project/go-state-types v0.11.0-rc2/go.mod h1:SyNPwTsU7I22gL2r0OAPcImvLoTVfgRwdK/Y5rR1zz8=
github.com/filecoin-project/go-state-types v0.11.1 h1:GDtCN9V18bYVwXDZe+vJXc6Ck+qY9OUaQqpoVlp1FAk=
github.com/filecoin-project/go-state-types v0.11.1/go.mod h1:SyNPwTsU7I22gL2r0OAPcImvLoTVfgRwdK/Y5rR1zz8=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v0.0.0-20200925172917-aaed5359be39/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk=
Expand Down Expand Up @@ -436,8 +436,8 @@ github.com/filecoin-project/storetheindex v0.4.30-0.20221114113647-683091f8e893
github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E=
github.com/filecoin-project/venus v0.9.2-0.20210331052540-ca4ea7bab5fa/go.mod h1:9IY4iNo5At3GMBUNa8we3aGL7zM3cFUNxy2rMpb86C0=
github.com/filecoin-project/venus v0.9.5/go.mod h1:ol4DC0omgbpszB6UNJB92zT0QfAkux974U7aiW89XvI=
github.com/filecoin-project/venus-auth v1.11.0-rc1 h1:dV8F4xXMokmW1DKfK/F3KFysX19YuDDmS6fXPpCSnOI=
github.com/filecoin-project/venus-auth v1.11.0-rc1/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs=
github.com/filecoin-project/venus-auth v1.11.0 h1:9PBswWxc113vqaHABMcRyMm+1BtlJCwOFTPQJg/OVtQ=
github.com/filecoin-project/venus-auth v1.11.0/go.mod h1:aBfIfNxQkdcY8Rk5wrQn9qRtJpH4RTDdc10Ac+ferzs=
github.com/filecoin-project/venus-sealer v1.0.3/go.mod h1:6cErhac2TkfheD/ii65kaZJYK2i5sY37ys3cGmfnfTA=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
Expand Down Expand Up @@ -782,8 +782,8 @@ github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo=
github.com/ipfs-force-community/go-jsonrpc v0.1.7 h1:e0ZTapGFhDY54j0QpRYN54Q3FHawUBQAM1KvXOzZtYY=
github.com/ipfs-force-community/go-jsonrpc v0.1.7/go.mod h1:jBSvPTl8V1N7gSTuCR4bis8wnQnIjHbRPpROol6iQKM=
github.com/ipfs-force-community/lotus v0.8.1-0.20230418033744-8d4f6744d906 h1:Ur8QayIXTotEZGbhmaF8ZBZKG+vDKnUyq5ZZpzGIJDs=
github.com/ipfs-force-community/lotus v0.8.1-0.20230418033744-8d4f6744d906/go.mod h1:jqYepaYuf0ZF34quyROFJyNuCSYceL5TiSYXHh3V5kY=
github.com/ipfs-force-community/lotus v0.8.1-0.20230423011510-75338a5bf2e1 h1:gqkZkXkuxKxgTRP8ZkvT3dNIDZ/pjiOIQiSUOtEL9/w=
github.com/ipfs-force-community/lotus v0.8.1-0.20230423011510-75338a5bf2e1/go.mod h1:ehYqU7BwwknSRdFd/0iou0WOTKaQcFsYbMeQ4d2C/Mo=
github.com/ipfs-force-community/metrics v1.0.1-0.20211022060227-11142a08b729 h1:elS3KmzAMVrcZpmP2RMEjs9Zlwh6LfhJTfYQdj4TREs=
github.com/ipfs-force-community/metrics v1.0.1-0.20211022060227-11142a08b729/go.mod h1:mn40SioMuKtjmRumHFy/fJ26Pn028XuDjUJE9dorjyw=
github.com/ipfs-force-community/venus-auth v0.0.0-20210409095239-6767c8e7ac9f/go.mod h1:1jzX/6nT1UiBC0p2BuA1ujKFnZwPndZhmOB89Nemd+w=
Expand Down
9 changes: 9 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,15 @@ func (p *Proxy) MpoolBatchPushUntrusted(in0 context.Context, in1 []*types.Signed
return cli.MpoolBatchPushUntrusted(in0, in1)
}

func (p *Proxy) MpoolGetConfig(in0 context.Context) (out0 *types.MpoolConfig, err error) {
cli, err := p.Select(types.EmptyTSK)
if err != nil {
err = fmt.Errorf("api MpoolGetConfig %v", err)
return
}
return cli.MpoolGetConfig(in0)
}

func (p *Proxy) MpoolGetNonce(in0 context.Context, in1 address.Address) (out0 uint64, err error) {
cli, err := p.Select(types.EmptyTSK)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions proxy/unsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,6 @@ func (p *UnSupport) MpoolClear(in0 context.Context, in1 bool) (err error) {
return cli.MpoolClear(in0, in1)
}

func (p *UnSupport) MpoolGetConfig(in0 context.Context) (out0 *types.MpoolConfig, err error) {
cli, err := p.Select(types.EmptyTSK)
if err != nil {
err = fmt.Errorf("api MpoolGetConfig %v", err)
return
}
return cli.MpoolGetConfig(in0)
}

func (p *UnSupport) MpoolPushUntrusted(in0 context.Context, in1 *types.SignedMessage) (out0 cid.Cid, err error) {
cli, err := p.Select(types.EmptyTSK)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package version

var Version = "0.5.0-rc1"
var Version = "0.5.1"

var CurrentCommit string