Skip to content

Commit

Permalink
fix: support non-f0 address as sender
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5459 committed Dec 8, 2023
1 parent cd4eefd commit aecd45a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
11 changes: 11 additions & 0 deletions damocles-manager/modules/impl/sectors/sender_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ func (s *SenderSelector) Select(ctx context.Context, mid abi.ActorID, senders []
}

func (s *SenderSelector) selectInner(ctx context.Context, mid abi.ActorID, senders []address.Address) (address.Address, error) {
// convert non-f0 address to f0 address
for i := range senders {
if senders[i].Protocol() != address.ID {
var err error
senders[i], err = s.chain.StateLookupID(ctx, senders[i], types.EmptyTSK)
if err != nil {
return address.Undef, fmt.Errorf("convert non-f3 address to f0 address %s: %w", senders[i], err)
}
}
}

maddr, err := address.NewIDAddress(uint64(mid))
if err != nil {
return address.Undef, err
Expand Down
15 changes: 12 additions & 3 deletions damocles-manager/modules/impl/sectors/sender_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,33 @@ func TestSelectSender(t *testing.T) {
BlockDelaySecs: 30,
}

mockChain.IMinerStateStruct.Internal.StateMinerInfo = func(_ctx context.Context, _maddr address.Address, _tsk types.TipSetKey) (types.MinerInfo, error) {
mockChain.IMinerStateStruct.Internal.StateMinerInfo = func(_ context.Context, _ address.Address, _ types.TipSetKey) (types.MinerInfo, error) {
return types.MinerInfo{
Owner: lo.Must(address.NewIDAddress(1000)),
Worker: lo.Must(address.NewIDAddress(2000)),
ControlAddresses: []address.Address{lo.Must(address.NewIDAddress(3000)), lo.Must(address.NewIDAddress(4000)), lo.Must(address.NewIDAddress(5000))},
}, nil
}

mockChain.IActorStruct.Internal.StateGetActor = func(_ctx context.Context, actor address.Address, _tsk types.TipSetKey) (*types.Actor, error) {
mockChain.IActorStruct.Internal.StateGetActor = func(_ context.Context, actor address.Address, _ types.TipSetKey) (*types.Actor, error) {
return &types.Actor{
Balance: balances[actor],
}, nil
}

id5000F3 := lo.Must(address.NewBLSAddress(lo.Times(address.BlsPublicKeyBytes, func(_ int) byte { return 0 })))
f3f0mapping := map[address.Address]address.Address{
id5000F3: lo.Must(address.NewIDAddress(5000)),
}

mockChain.IMinerStateStruct.Internal.StateLookupID = func(_ context.Context, addr address.Address, _ types.TipSetKey) (address.Address, error) {
return f3f0mapping[addr], nil
}

ctx := context.TODO()

sel := sectors.NewSenderSelector(&mockChain)
senders := []address.Address{lo.Must(address.NewIDAddress(2000)), lo.Must(address.NewIDAddress(9999)), lo.Must(address.NewIDAddress(5000)), lo.Must(address.NewIDAddress(1000))}
senders := []address.Address{lo.Must(address.NewIDAddress(2000)), lo.Must(address.NewIDAddress(9999)), id5000F3, lo.Must(address.NewIDAddress(1000))}
sender, err := sel.Select(ctx, 1, senders)
require.NoError(t, err)
require.Equal(t, lo.Must(address.NewIDAddress(5000)).String(), sender.String())
Expand Down

0 comments on commit aecd45a

Please sign in to comment.