address review
This commit is contained in:
parent
0f92bced9d
commit
f5b027eda3
@ -302,10 +302,28 @@ func checkBlockMessages(ctx context.Context, sm *stmgr.StateManager, cs *store.C
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgsFromBlockTemplate extracts the different types of messages from a block
|
// CreateBlockHeader generates the block header from the block template of
|
||||||
// template and populates the header for the next block to be proposed.
|
// the block being proposed.
|
||||||
func MsgsFromBlockTemplate(ctx context.Context, sm *stmgr.StateManager, next *types.BlockHeader,
|
func CreateBlockHeader(ctx context.Context, sm *stmgr.StateManager, pts *types.TipSet,
|
||||||
pts *types.TipSet, bt *api.BlockTemplate) ([]*types.Message, []*types.SignedMessage, error) {
|
bt *api.BlockTemplate) (*types.BlockHeader, []*types.Message, []*types.SignedMessage, error) {
|
||||||
|
|
||||||
|
st, recpts, err := sm.TipSetState(ctx, pts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, xerrors.Errorf("failed to load tipset state: %w", err)
|
||||||
|
}
|
||||||
|
next := &types.BlockHeader{
|
||||||
|
Miner: bt.Miner,
|
||||||
|
Parents: bt.Parents.Cids(),
|
||||||
|
Ticket: bt.Ticket,
|
||||||
|
ElectionProof: bt.Eproof,
|
||||||
|
|
||||||
|
BeaconEntries: bt.BeaconValues,
|
||||||
|
Height: bt.Epoch,
|
||||||
|
Timestamp: bt.Timestamp,
|
||||||
|
WinPoStProof: bt.WinningPoStProof,
|
||||||
|
ParentStateRoot: st,
|
||||||
|
ParentMessageReceipts: recpts,
|
||||||
|
}
|
||||||
|
|
||||||
var blsMessages []*types.Message
|
var blsMessages []*types.Message
|
||||||
var secpkMessages []*types.SignedMessage
|
var secpkMessages []*types.SignedMessage
|
||||||
@ -319,32 +337,32 @@ func MsgsFromBlockTemplate(ctx context.Context, sm *stmgr.StateManager, next *ty
|
|||||||
|
|
||||||
c, err := sm.ChainStore().PutMessage(ctx, &msg.Message)
|
c, err := sm.ChainStore().PutMessage(ctx, &msg.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
blsMsgCids = append(blsMsgCids, c)
|
blsMsgCids = append(blsMsgCids, c)
|
||||||
} else if msg.Signature.Type == crypto.SigTypeSecp256k1 {
|
} else if msg.Signature.Type == crypto.SigTypeSecp256k1 {
|
||||||
c, err := sm.ChainStore().PutMessage(ctx, msg)
|
c, err := sm.ChainStore().PutMessage(ctx, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
secpkMsgCids = append(secpkMsgCids, c)
|
secpkMsgCids = append(secpkMsgCids, c)
|
||||||
secpkMessages = append(secpkMessages, msg)
|
secpkMessages = append(secpkMessages, msg)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return nil, nil, xerrors.Errorf("unknown sig type: %d", msg.Signature.Type)
|
return nil, nil, nil, xerrors.Errorf("unknown sig type: %d", msg.Signature.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
store := sm.ChainStore().ActorStore(ctx)
|
store := sm.ChainStore().ActorStore(ctx)
|
||||||
blsmsgroot, err := ToMessagesArray(store, blsMsgCids)
|
blsmsgroot, err := ToMessagesArray(store, blsMsgCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, xerrors.Errorf("building bls amt: %w", err)
|
return nil, nil, nil, xerrors.Errorf("building bls amt: %w", err)
|
||||||
}
|
}
|
||||||
secpkmsgroot, err := ToMessagesArray(store, secpkMsgCids)
|
secpkmsgroot, err := ToMessagesArray(store, secpkMsgCids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, xerrors.Errorf("building secpk amt: %w", err)
|
return nil, nil, nil, xerrors.Errorf("building secpk amt: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mmcid, err := store.Put(store.Context(), &types.MsgMeta{
|
mmcid, err := store.Put(store.Context(), &types.MsgMeta{
|
||||||
@ -352,29 +370,29 @@ func MsgsFromBlockTemplate(ctx context.Context, sm *stmgr.StateManager, next *ty
|
|||||||
SecpkMessages: secpkmsgroot,
|
SecpkMessages: secpkmsgroot,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
next.Messages = mmcid
|
next.Messages = mmcid
|
||||||
|
|
||||||
aggSig, err := AggregateSignatures(blsSigs)
|
aggSig, err := AggregateSignatures(blsSigs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
next.BLSAggregate = aggSig
|
next.BLSAggregate = aggSig
|
||||||
pweight, err := sm.ChainStore().Weight(ctx, pts)
|
pweight, err := sm.ChainStore().Weight(ctx, pts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
next.ParentWeight = pweight
|
next.ParentWeight = pweight
|
||||||
|
|
||||||
baseFee, err := sm.ChainStore().ComputeBaseFee(ctx, pts)
|
baseFee, err := sm.ChainStore().ComputeBaseFee(ctx, pts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, xerrors.Errorf("computing base fee: %w", err)
|
return nil, nil, nil, xerrors.Errorf("computing base fee: %w", err)
|
||||||
}
|
}
|
||||||
next.ParentBaseFee = baseFee
|
next.ParentBaseFee = baseFee
|
||||||
|
|
||||||
return blsMessages, secpkMessages, err
|
return next, blsMessages, secpkMessages, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,11 +17,6 @@ func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api.
|
|||||||
return nil, xerrors.Errorf("failed to load parent tipset: %w", err)
|
return nil, xerrors.Errorf("failed to load parent tipset: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, recpts, err := filec.sm.TipSetState(ctx, pts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("failed to load tipset state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, lbst, err := stmgr.GetLookbackTipSetForRound(ctx, filec.sm, pts, bt.Epoch)
|
_, lbst, err := stmgr.GetLookbackTipSetForRound(ctx, filec.sm, pts, bt.Epoch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("getting lookback miner actor state: %w", err)
|
return nil, xerrors.Errorf("getting lookback miner actor state: %w", err)
|
||||||
@ -32,21 +27,7 @@ func (filec *FilecoinEC) CreateBlock(ctx context.Context, w api.Wallet, bt *api.
|
|||||||
return nil, xerrors.Errorf("failed to get miner worker: %w", err)
|
return nil, xerrors.Errorf("failed to get miner worker: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
next := &types.BlockHeader{
|
next, blsMessages, secpkMessages, err := consensus.CreateBlockHeader(ctx, filec.sm, pts, bt)
|
||||||
Miner: bt.Miner,
|
|
||||||
Parents: bt.Parents.Cids(),
|
|
||||||
Ticket: bt.Ticket,
|
|
||||||
ElectionProof: bt.Eproof,
|
|
||||||
|
|
||||||
BeaconEntries: bt.BeaconValues,
|
|
||||||
Height: bt.Epoch,
|
|
||||||
Timestamp: bt.Timestamp,
|
|
||||||
WinPoStProof: bt.WinningPoStProof,
|
|
||||||
ParentStateRoot: st,
|
|
||||||
ParentMessageReceipts: recpts,
|
|
||||||
}
|
|
||||||
|
|
||||||
blsMessages, secpkMessages, err := consensus.MsgsFromBlockTemplate(ctx, filec.sm, next, pts, bt)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("failed to process messages from block template: %w", err)
|
return nil, xerrors.Errorf("failed to process messages from block template: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("retry")
|
var log = logging.Logger("retry")
|
||||||
|
Loading…
Reference in New Issue
Block a user