Skip to content
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

analyzer/runtime: Register special runtime addresses #516

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
28 changes: 19 additions & 9 deletions analyzer/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"

sdkConfig "github.com/oasisprotocol/oasis-sdk/client-sdk/go/config"
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rewards"
sdkTypes "github.com/oasisprotocol/oasis-sdk/client-sdk/go/types"

"github.com/oasisprotocol/nexus/analyzer"
Expand Down Expand Up @@ -77,18 +76,29 @@ func (m *processor) StringifyDenomination(d sdkTypes.Denomination) string {
return d.String()
}

// Extends `batch` with a query that will register a module address derived from "<module>.<kind>".
// See `Address::from_module` in runtime-sdk (Rust) or equivalently NewAddressForModule in client-sdk (Go).
func registerModuleAddress(batch *storage.QueryBatch, module string, kind string) {
batch.Queue(
queries.AddressPreimageInsert,
sdkTypes.NewAddressForModule(module, []byte(kind)), // address. This is how the actual runtime derives its own special addresses. The computed value is often not exposed in client-sdk.
sdkTypes.AddressV0ModuleContext.Identifier, // context_identifier. Input to the derivation.
int32(sdkTypes.AddressV0ModuleContext.Version), // context_version. Input to the derivation.
module+"."+kind, // address_data. Input to the derivation; the part that's the most interesting to human readers.
)
}

// Implements BlockProcessor interface.
func (m *processor) PreWork(ctx context.Context) error {
batch := &storage.QueryBatch{}

// Register special addresses.
batch.Queue(
queries.AddressPreimageInsert,
rewards.RewardPoolAddress.String(), // oasis1qp7x0q9qahahhjas0xde8w0v04ctp4pqzu5mhjav on mainnet oasis-3
sdkTypes.AddressV0ModuleContext.Identifier, // context_identifier
int32(sdkTypes.AddressV0ModuleContext.Version), // context_version
"rewards.reward-pool", // address_data (reconstructed from NewAddressForModule())
)
// Register special addresses. Not all of these are exposed in the Go client SDK; search runtime-sdk (Rust) for `Address::from_module`.
registerModuleAddress(batch, "rewards", "reward-pool") // oasis1qp7x0q9qahahhjas0xde8w0v04ctp4pqzu5mhjav
registerModuleAddress(batch, "consensus_accounts", "pending-withdrawal") // oasis1qr677rv0dcnh7ys4yanlynysvnjtk9gnsyhvm6ln
registerModuleAddress(batch, "consensus_accounts", "pending-delegation") // oasis1qzcdegtf7aunxr5n5pw7n5xs3u7cmzlz9gwmq49r
registerModuleAddress(batch, "accounts", "common-pool") // oasis1qz78phkdan64g040cvqvqpwkplfqf6tj6uwcsh30
registerModuleAddress(batch, "accounts", "fee-accumulator") // oasis1qp3r8hgsnphajmfzfuaa8fhjag7e0yt35cjxq0u4

if err := m.target.SendBatch(ctx, batch); err != nil {
return err
}
Expand Down