2021-09-02 16:07:23 +00:00
|
|
|
package filcns
|
2019-07-05 14:46:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-09-06 20:03:28 +00:00
|
|
|
|
2019-08-27 00:46:39 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-07-08 15:14:36 +00:00
|
|
|
|
2020-04-09 00:24:10 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-09-02 16:45:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-07-05 14:46:21 +00:00
|
|
|
)
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api.BlockTemplate) (*types.FullBlock, error) {
|
2021-12-11 21:03:00 +00:00
|
|
|
pts, err := filec.sm.ChainStore().LoadTipSet(ctx, bt.Parents)
|
2020-04-09 00:24:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("failed to load parent tipset: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
_, lbst, err := stmgr.GetLookbackTipSetForRound(ctx, filec.sm, pts, bt.Epoch)
|
2020-10-21 23:08:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("getting lookback miner actor state: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
worker, err := stmgr.GetMinerWorkerRaw(ctx, filec.sm, lbst, bt.Miner)
|
2019-08-27 00:46:39 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("failed to get miner worker: %w", err)
|
|
|
|
}
|
2019-07-05 14:46:21 +00:00
|
|
|
|
2022-11-22 09:52:11 +00:00
|
|
|
next, blsMessages, secpkMessages, err := consensus.CreateBlockHeader(ctx, filec.sm, pts, bt)
|
2019-07-05 14:46:21 +00:00
|
|
|
if err != nil {
|
2022-09-27 07:31:48 +00:00
|
|
|
return nil, xerrors.Errorf("failed to process messages from block template: %w", err)
|
2019-07-05 14:46:21 +00:00
|
|
|
}
|
|
|
|
|
2022-10-03 07:29:42 +00:00
|
|
|
if err := signBlock(ctx, w, worker, next); err != nil {
|
2019-08-27 00:46:39 +00:00
|
|
|
return nil, xerrors.Errorf("failed to sign new block: %w", err)
|
|
|
|
}
|
|
|
|
|
2019-07-25 22:15:03 +00:00
|
|
|
fullBlock := &types.FullBlock{
|
2019-08-01 20:40:47 +00:00
|
|
|
Header: next,
|
|
|
|
BlsMessages: blsMessages,
|
|
|
|
SecpkMessages: secpkMessages,
|
2019-07-05 14:46:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return fullBlock, nil
|
|
|
|
}
|