-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: API: Implement StateLookupRobustAddress #8486
Merged
+147
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ import ( | |||||
"context" | ||||||
"sync" | ||||||
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||||||
|
||||||
"github.com/filecoin-project/specs-actors/v7/actors/migration/nv15" | ||||||
|
||||||
"github.com/filecoin-project/lotus/chain/rand" | ||||||
|
@@ -22,6 +24,7 @@ import ( | |||||
|
||||||
"github.com/filecoin-project/lotus/api" | ||||||
"github.com/filecoin-project/lotus/build" | ||||||
_init "github.com/filecoin-project/lotus/chain/actors/builtin/init" | ||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/paych" | ||||||
"github.com/filecoin-project/lotus/chain/actors/policy" | ||||||
"github.com/filecoin-project/lotus/chain/state" | ||||||
|
@@ -318,6 +321,48 @@ func (sm *StateManager) LookupID(ctx context.Context, addr address.Address, ts * | |||||
return state.LookupID(addr) | ||||||
} | ||||||
|
||||||
func (sm *StateManager) LookupRobustAddress(ctx context.Context, idAddr address.Address, ts *types.TipSet) (address.Address, error) { | ||||||
idAddrDecoded, err := address.IDFromAddress(idAddr) | ||||||
if err != nil { | ||||||
return address.Undef, xerrors.Errorf("failed to decode provided address as id addr: %w", err) | ||||||
} | ||||||
|
||||||
cst := cbor.NewCborStore(sm.cs.StateBlockstore()) | ||||||
wrapStore := adt.WrapStore(ctx, cst) | ||||||
|
||||||
stateTree, err := state.LoadStateTree(cst, sm.parentState(ts)) | ||||||
if err != nil { | ||||||
return address.Undef, xerrors.Errorf("load state tree: %w", err) | ||||||
} | ||||||
|
||||||
initActor, err := stateTree.GetActor(_init.Address) | ||||||
if err != nil { | ||||||
return address.Undef, xerrors.Errorf("load init actor: %w", err) | ||||||
} | ||||||
|
||||||
initState, err := _init.Load(wrapStore, initActor) | ||||||
if err != nil { | ||||||
return address.Undef, xerrors.Errorf("load init state: %w", err) | ||||||
} | ||||||
robustAddr := address.Undef | ||||||
|
||||||
err = initState.ForEachActor(func(id abi.ActorID, addr address.Address) error { | ||||||
if uint64(id) == idAddrDecoded { | ||||||
robustAddr = addr | ||||||
// Hacky way to early return from ForEach | ||||||
return xerrors.New("robust address found") | ||||||
} | ||||||
return nil | ||||||
}) | ||||||
if robustAddr == address.Undef { | ||||||
if err == nil { | ||||||
return address.Undef, xerrors.Errorf("Address %s not found", idAddr.String()) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
return address.Undef, xerrors.Errorf("finding address: %w", err) | ||||||
} | ||||||
return robustAddr, nil | ||||||
} | ||||||
|
||||||
func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) error { | ||||||
tschain := []*types.TipSet{ts} | ||||||
for ts.Height() != 0 { | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-state-types/network" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
"github.com/filecoin-project/lotus/itests/kit" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStateLookupRobustAddress(t *testing.T) { | ||
ctx := context.Background() | ||
kit.QuietMiningLogs() | ||
|
||
client, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.GenesisNetworkVersion(network.Version15)) | ||
ens.InterconnectAll().BeginMining(10 * time.Millisecond) | ||
|
||
addr, err := miner.ActorAddress(ctx) | ||
require.NoError(t, err) | ||
|
||
// Look up the robust address | ||
robAddr, err := client.StateLookupRobustAddress(ctx, addr, types.EmptyTSK) | ||
require.NoError(t, err) | ||
|
||
// Check the id address for the given robust address and make sure it matches | ||
idAddr, err := client.StateLookupID(ctx, robAddr, types.EmptyTSK) | ||
require.NoError(t, err) | ||
require.Equal(t, addr, idAddr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation this for sure is slow due to data structures. Do we want to allow anyone (including for example browser) to call this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kubuxu Our thought was that it should be treated roughly the same as
StateCompute
which is perm: read, and not in the gateway. We can bump the perm for sure, though, I think the use cases are very few for this (but some people really want it).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best to bump the StateCompute perm as well (we could add another permission
slow
or something).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good idea, but I think it'll be a future thing.