add tipset message was executed in back to waitmsg call

This commit is contained in:
whyrusleeping 2019-10-04 14:58:24 -06:00 committed by Łukasz Magiera
parent b8bc54fd5b
commit 84985ef96f
4 changed files with 11 additions and 9 deletions

View File

@ -195,6 +195,7 @@ type DealInfo struct {
type MsgWait struct {
Receipt types.MessageReceipt
TipSet *types.TipSet
}
type BlockMessages struct {

View File

@ -642,25 +642,25 @@ func (cs *ChainStore) LoadSignedMessagesFromCids(cids []cid.Cid) ([]*types.Signe
return msgs, nil
}
func (cs *ChainStore) WaitForMessage(ctx context.Context, mcid cid.Cid) (*types.MessageReceipt, error) {
func (cs *ChainStore) WaitForMessage(ctx context.Context, mcid cid.Cid) (*types.TipSet, *types.MessageReceipt, error) {
tsub := cs.SubHeadChanges(ctx)
head := cs.GetHeaviestTipSet()
r, err := cs.tipsetExecutedMessage(head, mcid)
if err != nil {
return nil, err
return nil, nil, err
}
if r != nil {
return r, nil
return head, r, nil
}
for {
select {
case notif, ok := <-tsub:
if !ok {
return nil, ctx.Err()
return nil, nil, ctx.Err()
}
for _, val := range notif {
switch val.Type {
@ -669,15 +669,15 @@ func (cs *ChainStore) WaitForMessage(ctx context.Context, mcid cid.Cid) (*types.
case HCApply:
r, err := cs.tipsetExecutedMessage(val.Val, mcid)
if err != nil {
return nil, err
return nil, nil, err
}
if r != nil {
return r, nil
return val.Val, r, nil
}
}
}
case <-ctx.Done():
return nil, ctx.Err()
return nil, nil, ctx.Err()
}
}
}

View File

@ -56,7 +56,7 @@ func tipsetSortFunc(blks []*BlockHeader) func(i, j int) bool {
tj := blks[j].LastTicket()
if ti.Equals(tj) {
//log.Warn("blocks have same ticket")
log.Warnf("blocks have same ticket (%s %s)", blks[i].Miner, blks[j].Miner)
return blks[i].Cid().KeyString() < blks[j].Cid().KeyString()
}

View File

@ -49,13 +49,14 @@ func (a *ChainAPI) ChainGetRandomness(ctx context.Context, pts *types.TipSet, ti
func (a *ChainAPI) ChainWaitMsg(ctx context.Context, msg cid.Cid) (*api.MsgWait, error) {
// TODO: consider using event system for this, expose confidence
recpt, err := a.Chain.WaitForMessage(ctx, msg)
ts, recpt, err := a.Chain.WaitForMessage(ctx, msg)
if err != nil {
return nil, err
}
return &api.MsgWait{
Receipt: *recpt,
TipSet: ts,
}, nil
}