mpool: Fix PushWithNonce for ID addresses
This commit is contained in:
parent
50a8b6a184
commit
918b759d03
@ -130,6 +130,7 @@ type Provider interface {
|
|||||||
PutMessage(m types.ChainMsg) (cid.Cid, error)
|
PutMessage(m types.ChainMsg) (cid.Cid, error)
|
||||||
PubSubPublish(string, []byte) error
|
PubSubPublish(string, []byte) error
|
||||||
StateGetActor(address.Address, *types.TipSet) (*types.Actor, error)
|
StateGetActor(address.Address, *types.TipSet) (*types.Actor, error)
|
||||||
|
StateAccountKey(context.Context, address.Address, *types.TipSet) (address.Address, error)
|
||||||
MessagesForBlock(*types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
|
MessagesForBlock(*types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
|
||||||
MessagesForTipset(*types.TipSet) ([]types.ChainMsg, error)
|
MessagesForTipset(*types.TipSet) ([]types.ChainMsg, error)
|
||||||
LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error)
|
LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error)
|
||||||
@ -161,6 +162,10 @@ func (mpp *mpoolProvider) StateGetActor(addr address.Address, ts *types.TipSet)
|
|||||||
return mpp.sm.GetActor(addr, ts)
|
return mpp.sm.GetActor(addr, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mpp *mpoolProvider) StateAccountKey(ctx context.Context, addr address.Address, ts *types.TipSet) (address.Address, error) {
|
||||||
|
return mpp.sm.ResolveToKeyAddress(ctx, addr, ts)
|
||||||
|
}
|
||||||
|
|
||||||
func (mpp *mpoolProvider) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
func (mpp *mpoolProvider) MessagesForBlock(h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
|
||||||
return mpp.sm.ChainStore().MessagesForBlock(h)
|
return mpp.sm.ChainStore().MessagesForBlock(h)
|
||||||
}
|
}
|
||||||
@ -470,22 +475,28 @@ func (mp *MessagePool) getStateBalance(addr address.Address, ts *types.TipSet) (
|
|||||||
return act.Balance, nil
|
return act.Balance, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mp *MessagePool) PushWithNonce(addr address.Address, cb func(uint64) (*types.SignedMessage, error)) (*types.SignedMessage, error) {
|
func (mp *MessagePool) PushWithNonce(ctx context.Context, addr address.Address, cb func(address.Address, uint64) (*types.SignedMessage, error)) (*types.SignedMessage, error) {
|
||||||
mp.curTsLk.Lock()
|
mp.curTsLk.Lock()
|
||||||
defer mp.curTsLk.Unlock()
|
defer mp.curTsLk.Unlock()
|
||||||
|
|
||||||
mp.lk.Lock()
|
mp.lk.Lock()
|
||||||
defer mp.lk.Unlock()
|
defer mp.lk.Unlock()
|
||||||
if addr.Protocol() == address.ID {
|
|
||||||
log.Warnf("Called pushWithNonce with ID address (%s) this might not be handled properly yet", addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
nonce, err := mp.getNonceLocked(addr, mp.curTs)
|
nonce, err := mp.getNonceLocked(addr, mp.curTs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("get nonce locked failed: %w", err)
|
return nil, xerrors.Errorf("get nonce locked failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg, err := cb(nonce)
|
fromKey := addr
|
||||||
|
if fromKey.Protocol() == address.ID {
|
||||||
|
fromKey, err = mp.api.StateAccountKey(ctx, fromKey, mp.curTs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, xerrors.Errorf("resolving sender key: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
msg, err := cb(fromKey, nonce)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,12 @@ func (n *ClientNodeAdapter) ListStorageProviders(ctx context.Context, encodedTs
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *ClientNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Signature, addr address.Address, input []byte, encodedTs shared.TipSetToken) (bool, error) {
|
func (n *ClientNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Signature, addr address.Address, input []byte, encodedTs shared.TipSetToken) (bool, error) {
|
||||||
err := sigs.Verify(&sig, addr, input)
|
addr, err := n.StateAccountKey(ctx, addr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = sigs.Verify(&sig, addr, input)
|
||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +337,11 @@ func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Add
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signer, err = n.StateAccountKey(ctx, signer, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
sig, err := n.Wallet.Sign(ctx, signer, buf)
|
sig, err := n.Wallet.Sign(ctx, signer, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -118,7 +118,12 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *ProviderNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Signature, addr address.Address, input []byte, encodedTs shared.TipSetToken) (bool, error) {
|
func (n *ProviderNodeAdapter) VerifySignature(ctx context.Context, sig crypto.Signature, addr address.Address, input []byte, encodedTs shared.TipSetToken) (bool, error) {
|
||||||
err := sigs.Verify(&sig, addr, input)
|
addr, err := n.StateAccountKey(ctx, addr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = sigs.Verify(&sig, addr, input)
|
||||||
return err == nil, err
|
return err == nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*t
|
|||||||
return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce)
|
return nil, xerrors.Errorf("MpoolPushMessage expects message nonce to be 0, was %d", msg.Nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.Mpool.PushWithNonce(msg.From, func(nonce uint64) (*types.SignedMessage, error) {
|
return a.Mpool.PushWithNonce(ctx, msg.From, func(from address.Address, nonce uint64) (*types.SignedMessage, error) {
|
||||||
msg.Nonce = nonce
|
msg.Nonce = nonce
|
||||||
|
|
||||||
b, err := a.WalletBalance(ctx, msg.From)
|
b, err := a.WalletBalance(ctx, msg.From)
|
||||||
@ -103,7 +103,7 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*t
|
|||||||
return nil, xerrors.Errorf("mpool push: not enough funds: %s < %s", b, msg.Value)
|
return nil, xerrors.Errorf("mpool push: not enough funds: %s < %s", b, msg.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.WalletSignMessage(ctx, msg.From, msg)
|
return a.WalletSignMessage(ctx, from, msg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user