Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions relayer/chainreader/chainreader_util/package_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (pr *PackageResolver) ResolvePackageAddress(moduleName string) (string, err
}

// ResolvePackageIds gets all package IDs for a module (including upgrades)
func (pr *PackageResolver) ResolvePackageIDs(ctx context.Context, moduleName string, signerAddress string) ([]string, error) {
func (pr *PackageResolver) ResolvePackageIDs(ctx context.Context, moduleName string) ([]string, error) {
moduleName = common.NormalizeName(moduleName)

packageAddress, err := pr.ResolvePackageAddress(moduleName)
Expand All @@ -132,7 +132,7 @@ func (pr *PackageResolver) ResolvePackageIDs(ctx context.Context, moduleName str
}
}

packageIDs, err := pr.client.LoadModulePackageIds(ctx, packageAddress, moduleName, signerAddress)
packageIDs, err := pr.client.LoadModulePackageIds(ctx, packageAddress, moduleName)
if err != nil {
return nil, fmt.Errorf("failed to load package IDs for module %s: %w", moduleName, err)
}
Expand All @@ -148,7 +148,7 @@ func (pr *PackageResolver) ResolvePackageIDs(ctx context.Context, moduleName str
}

// ResolveLatestPackageId gets the latest (most recent) package ID for a module
func (pr *PackageResolver) ResolveLatestPackageID(ctx context.Context, moduleName string, signerAddress string) (string, error) {
func (pr *PackageResolver) ResolveLatestPackageID(ctx context.Context, moduleName string) (string, error) {
moduleName = common.NormalizeName(moduleName)

packageAddress, err := pr.ResolvePackageAddress(moduleName)
Expand All @@ -163,7 +163,7 @@ func (pr *PackageResolver) ResolveLatestPackageID(ctx context.Context, moduleNam
}
}

latestID, err := pr.client.GetLatestPackageId(ctx, packageAddress, moduleName, signerAddress)
latestID, err := pr.client.GetLatestPackageId(ctx, packageAddress, moduleName)
if err != nil {
return "", fmt.Errorf("failed to get latest package ID for module %s: %w", moduleName, err)
}
Expand Down Expand Up @@ -206,8 +206,8 @@ func (pr *PackageResolver) ParseIdentifier(identifier string) (*ResolvedIdentifi
}

// ResolveIdentifier resolves a module name to latest package ID and creates full identifier
func (pr *PackageResolver) ResolveIdentifier(ctx context.Context, moduleName string, functionName string, signerAddress string) (*ResolvedIdentifier, error) {
latestPackageID, err := pr.ResolveLatestPackageID(ctx, moduleName, signerAddress)
func (pr *PackageResolver) ResolveIdentifier(ctx context.Context, moduleName string, functionName string) (*ResolvedIdentifier, error) {
latestPackageID, err := pr.ResolveLatestPackageID(ctx, moduleName)
if err != nil {
return nil, fmt.Errorf("failed to resolve latest package ID: %w", err)
}
Expand Down
13 changes: 11 additions & 2 deletions relayer/chainreader/reader/chainreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,17 @@ func (s *suiChainReader) Bind(ctx context.Context, bindings []pkgtypes.BoundCont

// If the "OffRamp" package/module is now bound, set the offramp package ID for the tx indexer
if pkg, err := s.packageResolver.ResolvePackageAddress(offrampName); err == nil {
// Get the latest package ID for the offramp module
latestPackageID, err := s.client.GetLatestPackageId(ctx, pkg, "offramp")
if err != nil {
s.logger.Warnw("Failed to get latest package ID for OffRamp", "error", err)
} else {
s.indexer.GetTransactionIndexer().SetOffRampPackage(latestPackageID)
}

s.indexer.GetTransactionIndexer().SetOffRampPackage(pkg)
}

return nil
}

Expand Down Expand Up @@ -654,7 +663,7 @@ func (s *suiChainReader) fetchGenericDependency(ctx context.Context, signerAddre
return "", fmt.Errorf("failed to get CCIP package ID from offramp package address in fetchGenericDependency: %w", err)
}

latestCcipPackageAddress, err := s.client.GetLatestPackageId(ctx, ccipPackageAddress, "state_object", signerAddress)
latestCcipPackageAddress, err := s.client.GetLatestPackageId(ctx, ccipPackageAddress, "state_object")
if err != nil {
return "", fmt.Errorf("failed to get latest CCIP package address from offramp package address in fetchGenericDependency: %w", err)
}
Expand Down Expand Up @@ -881,7 +890,7 @@ func (s *suiChainReader) executeFunction(ctx context.Context, parsed *readIdenti

// Override the package ID with the latest package ID of the module being called.
// This ensure we are always using the latestPkgID in case of upgrades.
latestPackageId, err := s.client.GetLatestPackageId(ctx, parsed.address, common.GetModuleForContract(parsed.contractName), "")
latestPackageId, err := s.client.GetLatestPackageId(ctx, parsed.address, common.GetModuleForContract(parsed.contractName))
if err != nil {
return []any{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions relayer/chainwriter/ptb/offramp/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ func BuildOffRampExecutePTB(
}

// Get the latest package ID from the offramp module
latestOfframpPackageId, err := ptbClient.GetLatestPackageId(ctx, addressMappings.OffRampPackageId, "offramp", signerAddress)
latestOfframpPackageId, err := ptbClient.GetLatestPackageId(ctx, addressMappings.OffRampPackageId, "offramp")
if err != nil {
return err
}

latestCcipPackageId, err := ptbClient.GetLatestPackageId(ctx, addressMappings.CcipPackageId, "state_object", signerAddress)
latestCcipPackageId, err := ptbClient.GetLatestPackageId(ctx, addressMappings.CcipPackageId, "state_object")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion relayer/chainwriter/ptb/ptb_constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (p *PTBConstructor) BuildPTBCommands(ctx context.Context, moduleName string
// Override the package ID with the latest package ID of the module being called,
// fallback to the provided package ID if the module does not have the `get_latest_package_id` function
if cmd.PackageId != nil && cmd.ModuleId != nil {
latestPackageId, err := p.client.GetLatestPackageId(ctx, *cmd.PackageId, *cmd.ModuleId, signerAddress)
latestPackageId, err := p.client.GetLatestPackageId(ctx, *cmd.PackageId, *cmd.ModuleId)
if err != nil {
return nil, fmt.Errorf("failed to get latest package id: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions relayer/client/mocks/mock_ptb_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions relayer/client/ptb_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ type SuiPTBClient interface {
GetLatestEpoch(ctx context.Context) (string, error)
GetNormalizedModule(ctx context.Context, packageId string, moduleId string) (models.GetNormalizedMoveModuleResponse, error)
GetSUIBalance(ctx context.Context, address string) (*big.Int, error)
LoadModulePackageIds(ctx context.Context, packageId string, module string, signerAddress string) ([]string, error)
GetLatestPackageId(ctx context.Context, packageId string, module string, signerAddress string) (string, error)
LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error)
GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error)
GetClient() sui.ISuiAPI
GetCache() *cache.Cache
GetCachedValue(key string) (any, bool)
Expand Down Expand Up @@ -1002,18 +1002,18 @@ func (c *PTBClient) getNormalizedModuleInternal(ctx context.Context, packageId s

// LoadModulePackages returns the set of package IDs for a given module using its original package ID
// This method assumes that module names are unique across all packages
func (c *PTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string, signerAddress string) ([]string, error) {
func (c *PTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error) {
var result []string
err := c.WithRateLimit(ctx, "LoadModulePackageIds", func(ctx context.Context) error {
var err error
result, err = c.loadModulePackageIdsInternal(ctx, packageId, module, signerAddress)
result, err = c.loadModulePackageIdsInternal(ctx, packageId, module)
return err
})
return result, err
}

// loadModulePackageIdsInternal is the internal implementation without rate limiting
func (c *PTBClient) loadModulePackageIdsInternal(ctx context.Context, packageId string, module string, signerAddress string) ([]string, error) {
func (c *PTBClient) loadModulePackageIdsInternal(ctx context.Context, packageId string, module string) ([]string, error) {
// Ensure that the module keeps track of its package IDs by checking that it has `add_package_id` function
normalizedModule, err := c.getNormalizedModuleInternal(ctx, packageId, module)
if err != nil {
Expand Down Expand Up @@ -1125,20 +1125,20 @@ func (c *PTBClient) loadModulePackageIdsInternal(ctx context.Context, packageId
return packageIds, nil
}

func (c *PTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string, signerAddress string) (string, error) {
func (c *PTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error) {
var result string
err := c.WithRateLimit(ctx, "GetLatestPackageId", func(ctx context.Context) error {
var err error
result, err = c.getLatestPackageIdInternal(ctx, packageId, module, signerAddress)
result, err = c.getLatestPackageIdInternal(ctx, packageId, module)
return err
})
return result, err
}

// getLatestPackageIdInternal is the internal implementation without rate limiting
func (c *PTBClient) getLatestPackageIdInternal(ctx context.Context, packageId string, module string, signerAddress string) (string, error) {
func (c *PTBClient) getLatestPackageIdInternal(ctx context.Context, packageId string, module string) (string, error) {
// Use internal method to avoid nested semaphore acquisition
packageIds, err := c.loadModulePackageIdsInternal(ctx, packageId, module, signerAddress)
packageIds, err := c.loadModulePackageIdsInternal(ctx, packageId, module)
if err != nil {
return "", fmt.Errorf("failed to load module package ids: %w", err)
}
Expand Down
1 change: 0 additions & 1 deletion relayer/client/ptb_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ func TestPTBClient(t *testing.T) {
context.Background(),
packageId,
"counter",
packageId,
)

// The latest package ID should be the same as the provided package ID
Expand Down
8 changes: 4 additions & 4 deletions relayer/testutils/fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ func (c *FakeSuiPTBClient) SuiXGetReferenceGasPrice(ctx context.Context) (string
return "1000", nil
}

func (c *FakeSuiPTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string, signerAddress string) (string, error) {
func (c *FakeSuiPTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error) {
// Return the provided package ID as the latest for testing
return packageId, nil
}

func (c *FakeSuiPTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string, signerAddress string) ([]string, error) {
func (c *FakeSuiPTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error) {
// Return a single package ID for testing
return []string{packageId}, nil
}
Expand Down Expand Up @@ -291,11 +291,11 @@ func (c *StatefulFakeSuiPTBClient) FinishPTBAndSend(ctx context.Context, txnSign
return client.SuiTransactionBlockResponse{}, nil
}

func (c *StatefulFakeSuiPTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string, signerAddress string) (string, error) {
func (c *StatefulFakeSuiPTBClient) GetLatestPackageId(ctx context.Context, packageId string, module string) (string, error) {
return "", nil
}

func (c *StatefulFakeSuiPTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string, signerAddress string) ([]string, error) {
func (c *StatefulFakeSuiPTBClient) LoadModulePackageIds(ctx context.Context, packageId string, module string) ([]string, error) {
return []string{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion sui.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stdenv.mkDerivation rec {
src = if stdenv.hostPlatform.isDarwin then
pkgs.fetchzip {
url = "https://github.com/MystenLabs/sui/releases/download/mainnet-v${version}/sui-mainnet-v${version}-macos-arm64.tgz"; # Assume is a M1 Mac
sha256 = "sha256-/rcMuLEgqV9UA0K7VaS+wIpX+jQKDQE+U1vGb5spJmU="; # Should be replaced when bumping versions
sha256 = "sha256-0w8YYrDDbf0tWom2asp0BkzuqLmWbdcUAAkMAll7Q6Y="; # Should be replaced when bumping versions
stripRoot = false;
}
else if stdenv.isLinux then
Expand Down
Loading