-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6371 from beeleelee/feat/f3
[wip] f3 integration for venus
- Loading branch information
Showing
27 changed files
with
921 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package f3 | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-f3/certs" | ||
"github.com/filecoin-project/venus/venus-shared/api/f3" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
var _ f3.F3 = &f3API{} | ||
|
||
type f3API struct { | ||
f3module *F3Submodule | ||
} | ||
|
||
var ErrF3Disabled = errors.New("f3 is disabled") | ||
|
||
func (f3api *f3API) F3Participate(ctx context.Context, miner address.Address) (<-chan string, error) { | ||
|
||
if f3api.f3module.F3 == nil { | ||
log.Infof("F3Participate called for %v, F3 is disabled", miner) | ||
return nil, ErrF3Disabled | ||
} | ||
|
||
// Make channel with some buffer to avoid blocking under higher load. | ||
errCh := make(chan string, 4) | ||
log.Infof("starting F3 participation for %v", miner) | ||
|
||
actorID, err := address.IDFromAddress(miner) | ||
if err != nil { | ||
return nil, xerrors.Errorf("miner address in F3Participate not of ID type: %w", err) | ||
} | ||
|
||
// Participate takes control of closing the channel | ||
go f3api.f3module.F3.Participate(ctx, actorID, errCh) | ||
return errCh, nil | ||
} | ||
|
||
func (f3api *f3API) F3GetCertificate(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error) { | ||
if f3api.f3module.F3 == nil { | ||
return nil, ErrF3Disabled | ||
} | ||
return f3api.f3module.F3.GetCert(ctx, instance) | ||
} | ||
|
||
func (f3api *f3API) F3GetLatestCertificate(ctx context.Context) (*certs.FinalityCertificate, error) { | ||
if f3api.f3module.F3 == nil { | ||
return nil, ErrF3Disabled | ||
} | ||
return f3api.f3module.F3.GetLatestCert(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package f3 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/filecoin-project/venus/app/submodule/chain" | ||
"github.com/filecoin-project/venus/app/submodule/network" | ||
"github.com/filecoin-project/venus/pkg/repo" | ||
"github.com/filecoin-project/venus/pkg/vf3" | ||
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1" | ||
"github.com/filecoin-project/venus/venus-shared/api/f3" | ||
logging "github.com/ipfs/go-log" | ||
) | ||
|
||
var log = logging.Logger("f3") | ||
|
||
type F3Submodule struct { | ||
F3 *vf3.F3 | ||
} | ||
|
||
func NewF3Submodule(ctx context.Context, repo repo.Repo, chain *chain.ChainSubmodule, network *network.NetworkSubmodule, walletAPI v1api.IWallet) (*F3Submodule, error) { | ||
netconf := repo.Config().NetworkParams | ||
if !netconf.F3Enabled { | ||
return &F3Submodule{ | ||
F3: &vf3.F3{}, | ||
}, nil | ||
} | ||
m, err := vf3.New(ctx, vf3.F3Params{ | ||
NetworkName: network.NetworkName, | ||
NetworkParams: netconf, | ||
PubSub: network.Pubsub, | ||
Host: network.Host, | ||
ChainStore: chain.ChainReader, | ||
StateManager: chain.Stmgr, | ||
Datastore: repo.ChainDatastore(), | ||
Wallet: walletAPI, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &F3Submodule{m}, nil | ||
} | ||
|
||
func (m *F3Submodule) API() f3.F3 { | ||
return &f3API{ | ||
f3module: m, | ||
} | ||
} | ||
|
||
func (m *F3Submodule) V0API() f3.F3 { | ||
return &f3API{ | ||
f3module: m, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.