Skip to content

Commit

Permalink
chore: sync: cleanup sync serve and reduce log noise (#11543)
Browse files Browse the repository at this point in the history
* chore: cleanup sync serve and reduce log noise

1. Demote a noisy blocksync request error to debug. All this warning
means is that someone is requesting a tipset we don't have.
2. Add a separate warning if we fail to collect a chain. If we have the
tipsets but fail to collect the chain, something is actually wrong.
3. Fix a TODO and return a single CompactedMessages rather than 4
separate values.

* generally reduce the warning to info

It turns out we do fail to gather messages frequently as well, likely
because we have written the tipsets but haven't fetched the messages...
  • Loading branch information
Stebalien authored Jan 29, 2024
1 parent 6cbeb9a commit 4d73feb
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions chain/exchange/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (s *server) serviceRequest(ctx context.Context, req *validatedRequest) (*Re

chain, err := collectChainSegment(ctx, s.cs, req)
if err != nil {
log.Warn("block sync request: collectChainSegment failed: ", err)
log.Info("block sync request: collectChainSegment failed: ", err)
return &Response{
Status: InternalError,
ErrorMessage: err.Error(),
Expand Down Expand Up @@ -171,17 +171,11 @@ func collectChainSegment(ctx context.Context, cs *store.ChainStore, req *validat
}

if req.options.IncludeMessages {
bmsgs, bmincl, smsgs, smincl, err := gatherMessages(ctx, cs, ts)
bst.Messages, err = gatherMessages(ctx, cs, ts)
if err != nil {
return nil, xerrors.Errorf("gather messages failed: %w", err)
}

// FIXME: Pass the response to `gatherMessages()` and set all this there.
bst.Messages = &CompactedMessages{}
bst.Messages.Bls = bmsgs
bst.Messages.BlsIncludes = bmincl
bst.Messages.Secpk = smsgs
bst.Messages.SecpkIncludes = smincl
}

bstips = append(bstips, &bst)
Expand All @@ -196,16 +190,16 @@ func collectChainSegment(ctx context.Context, cs *store.ChainStore, req *validat
}
}

func gatherMessages(ctx context.Context, cs *store.ChainStore, ts *types.TipSet) ([]*types.Message, [][]uint64, []*types.SignedMessage, [][]uint64, error) {
func gatherMessages(ctx context.Context, cs *store.ChainStore, ts *types.TipSet) (*CompactedMessages, error) {
msgs := new(CompactedMessages)
blsmsgmap := make(map[cid.Cid]uint64)
secpkmsgmap := make(map[cid.Cid]uint64)
var secpkincl, blsincl [][]uint64

var blscids, secpkcids []cid.Cid
for _, block := range ts.Blocks() {
bc, sc, err := cs.ReadMsgMetaCids(ctx, block.Messages)
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}

// FIXME: DRY. Use `chain.Message` interface.
Expand All @@ -220,7 +214,7 @@ func gatherMessages(ctx context.Context, cs *store.ChainStore, ts *types.TipSet)

bmi = append(bmi, i)
}
blsincl = append(blsincl, bmi)
msgs.BlsIncludes = append(msgs.BlsIncludes, bmi)

smi := make([]uint64, 0, len(sc))
for _, m := range sc {
Expand All @@ -233,18 +227,19 @@ func gatherMessages(ctx context.Context, cs *store.ChainStore, ts *types.TipSet)

smi = append(smi, i)
}
secpkincl = append(secpkincl, smi)
msgs.SecpkIncludes = append(msgs.SecpkIncludes, smi)
}

blsmsgs, err := cs.LoadMessagesFromCids(ctx, blscids)
var err error
msgs.Bls, err = cs.LoadMessagesFromCids(ctx, blscids)
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}

secpkmsgs, err := cs.LoadSignedMessagesFromCids(ctx, secpkcids)
msgs.Secpk, err = cs.LoadSignedMessagesFromCids(ctx, secpkcids)
if err != nil {
return nil, nil, nil, nil, err
return nil, err
}

return blsmsgs, blsincl, secpkmsgs, secpkincl, nil
return msgs, nil
}

0 comments on commit 4d73feb

Please sign in to comment.