Skip to content

Commit

Permalink
init add pontusx dev support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew7234 committed May 21, 2024
1 parent c596cdc commit 61844ef
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 58 deletions.
1 change: 1 addition & 0 deletions analyzer/aggregate_stats/aggregate_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var statsLayers = []string{
string(common.RuntimeEmerald),
string(common.RuntimeSapphire),
string(common.RuntimePontusx),
string(common.RuntimePontusxdev),
string(common.RuntimeCipher),
}

Expand Down
14 changes: 8 additions & 6 deletions analyzer/evmverifier/sourcify/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ const (
// https://docs.sourcify.dev/docs/chains/
var sourcifyChains = map[common.ChainName]map[common.Runtime]string{
common.ChainNameTestnet: {
common.RuntimeEmerald: "42261",
common.RuntimeSapphire: "23295",
common.RuntimePontusx: "23295", // XXX: We're stealing sapphire data here. TODO: use dedicated verifications.
common.RuntimeEmerald: "42261",
common.RuntimeSapphire: "23295",
common.RuntimePontusx: "23295", // XXX: We're stealing sapphire data here. TODO: use dedicated verifications.
common.RuntimePontusxdev: "23295", // XXX: We're stealing sapphire data here. TODO: use dedicated verifications.
},
common.ChainNameMainnet: {
common.RuntimeEmerald: "42262",
common.RuntimeSapphire: "23294",
common.RuntimePontusx: "23294", // XXX: We're stealing sapphire data here. TODO: use dedicated verifications.
common.RuntimeEmerald: "42262",
common.RuntimeSapphire: "23294",
common.RuntimePontusx: "23294", // XXX: We're stealing sapphire data here. TODO: use dedicated verifications.
common.RuntimePontusxdev: "23294", // XXX: We're stealing sapphire data here. TODO: use dedicated verifications.
},
}

Expand Down
2 changes: 2 additions & 0 deletions api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ func RuntimeFromURLMiddleware(baseURL string) func(next http.Handler) http.Handl
runtime = common.RuntimeCipher
case strings.HasPrefix(path, "/pontusx/"):
runtime = common.RuntimePontusx
case strings.HasPrefix(path, "/pontusxdev/"):
runtime = common.RuntimePontusxdev
}

if runtime != "" {
Expand Down
4 changes: 2 additions & 2 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1241,13 +1241,13 @@ components:
type: string
# NOTE: Change IsValid() in util.go if you change this.
# https://github.com/oasisprotocol/nexus/blob/v0.0.16/api/v1/types/util.go#L40
enum: [emerald, sapphire, pontusx, cipher, consensus]
enum: [emerald, sapphire, pontusx, pontusxdev, cipher, consensus]

Runtime:
type: string
# NOTE: Change IsValid() in util.go if you change this.
# https://github.com/oasisprotocol/nexus/blob/v0.0.16/api/v1/types/util.go#L49
enum: [emerald, sapphire, pontusx, cipher]
enum: [emerald, sapphire, pontusx, pontusxdev, cipher]

StakingAddress:
type: string
Expand Down
4 changes: 2 additions & 2 deletions api/v1/types/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c ConsensusEventType) IsValid() bool {

func (c Layer) IsValid() bool {
switch c {
case LayerConsensus, LayerCipher, LayerEmerald, LayerSapphire, LayerPontusx:
case LayerConsensus, LayerCipher, LayerEmerald, LayerSapphire, LayerPontusx, LayerPontusxdev:
return true
default:
return false
Expand All @@ -52,7 +52,7 @@ func (c Layer) IsValid() bool {

func (c Runtime) IsValid() bool {
switch c {
case RuntimeCipher, RuntimeEmerald, RuntimeSapphire, RuntimePontusx:
case RuntimeCipher, RuntimeEmerald, RuntimeSapphire, RuntimePontusx, RuntimePontusxdev:
return true
default:
return false
Expand Down
73 changes: 68 additions & 5 deletions cmd/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,12 @@ func addAnalyzer(analyzers []SyncedAnalyzer, errSoFar error, syncTag string, ana
}

var (
syncTagConsensus = "consensus"
syncTagEmerald = string(common.RuntimeEmerald)
syncTagSapphire = string(common.RuntimeSapphire)
syncTagCipher = string(common.RuntimeCipher)
syncTagPontusx = string(common.RuntimePontusx)
syncTagConsensus = "consensus"
syncTagEmerald = string(common.RuntimeEmerald)
syncTagSapphire = string(common.RuntimeSapphire)
syncTagCipher = string(common.RuntimeCipher)
syncTagPontusx = string(common.RuntimePontusx)
syncTagPontusxdev = string(common.RuntimePontusxdev)
)

// NewService creates new Service.
Expand Down Expand Up @@ -330,6 +331,7 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
addFastSyncRuntimeAnalyzers(common.RuntimeEmerald, cfg.Analyzers.Emerald)
addFastSyncRuntimeAnalyzers(common.RuntimeSapphire, cfg.Analyzers.Sapphire)
addFastSyncRuntimeAnalyzers(common.RuntimePontusx, cfg.Analyzers.Pontusx)
addFastSyncRuntimeAnalyzers(common.RuntimePontusxdev, cfg.Analyzers.Pontusxdev)
addFastSyncRuntimeAnalyzers(common.RuntimeCipher, cfg.Analyzers.Cipher)

// Initialize slow-sync analyzers.
Expand Down Expand Up @@ -373,6 +375,16 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return runtime.NewRuntimeAnalyzer(cfg.Source.ChainName, common.RuntimePontusx, runtimeMetadata, cfg.Analyzers.Pontusx.SlowSyncRange(), cfg.Analyzers.Pontusx.BatchSize, analyzer.SlowSyncMode, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.Pontusxdev != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
runtimeMetadata := cfg.Source.SDKParaTime(common.RuntimePontusxdev)
sourceClient, err1 := sources.Runtime(ctx, common.RuntimePontusxdev)
if err1 != nil {
return nil, err1
}
return runtime.NewRuntimeAnalyzer(cfg.Source.ChainName, common.RuntimePontusxdev, runtimeMetadata, cfg.Analyzers.Pontusxdev.SlowSyncRange(), cfg.Analyzers.Pontusx.BatchSize, analyzer.SlowSyncMode, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.Cipher != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagCipher, func() (A, error) {
runtimeMetadata := cfg.Source.SDKParaTime(common.RuntimeCipher)
Expand Down Expand Up @@ -410,6 +422,15 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return evmtokens.NewAnalyzer(common.RuntimePontusx, cfg.Analyzers.PontusxEvmTokens.ItemBasedAnalyzerConfig, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.PontusxdevEvmTokens != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
sourceClient, err1 := sources.Runtime(ctx, common.RuntimePontusxdev)
if err1 != nil {
return nil, err1
}
return evmtokens.NewAnalyzer(common.RuntimePontusxdev, cfg.Analyzers.PontusxdevEvmTokens.ItemBasedAnalyzerConfig, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.EmeraldEvmNfts != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagEmerald, func() (A, error) {
sourceClient, err1 := sources.Runtime(ctx, common.RuntimeEmerald)
Expand Down Expand Up @@ -449,6 +470,19 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return evmnfts.NewAnalyzer(common.RuntimePontusx, cfg.Analyzers.PontusxEvmNfts.ItemBasedAnalyzerConfig, sourceClient, ipfsClient, dbClient, logger)
})
}
if cfg.Analyzers.PontusxdevEvmNfts != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
sourceClient, err1 := sources.Runtime(ctx, common.RuntimePontusxdev)
if err1 != nil {
return nil, err1
}
ipfsClient, err1 := sources.IPFS(ctx)
if err1 != nil {
return nil, err1
}
return evmnfts.NewAnalyzer(common.RuntimePontusxdev, cfg.Analyzers.PontusxdevEvmNfts.ItemBasedAnalyzerConfig, sourceClient, ipfsClient, dbClient, logger)
})
}
if cfg.Analyzers.EmeraldEvmTokenBalances != nil {
runtimeMetadata := cfg.Source.SDKParaTime(common.RuntimeEmerald)
analyzers, err = addAnalyzer(analyzers, err, syncTagEmerald, func() (A, error) {
Expand Down Expand Up @@ -479,6 +513,16 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return evmtokenbalances.NewAnalyzer(common.RuntimePontusx, cfg.Analyzers.PontusxEvmTokenBalances.ItemBasedAnalyzerConfig, runtimeMetadata, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.PontusxdevEvmTokenBalances != nil {
runtimeMetadata := cfg.Source.SDKParaTime(common.RuntimePontusxdev)
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
sourceClient, err1 := sources.Runtime(ctx, common.RuntimePontusxdev)
if err1 != nil {
return nil, err1
}
return evmtokenbalances.NewAnalyzer(common.RuntimePontusxdev, cfg.Analyzers.PontusxdevEvmTokenBalances.ItemBasedAnalyzerConfig, runtimeMetadata, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.EmeraldContractCode != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagEmerald, func() (A, error) {
sourceClient, err1 := sources.Runtime(ctx, common.RuntimeEmerald)
Expand Down Expand Up @@ -506,6 +550,15 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return evmcontractcode.NewAnalyzer(common.RuntimePontusx, cfg.Analyzers.PontusxContractCode.ItemBasedAnalyzerConfig, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.PontusxdevContractCode != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
sourceClient, err1 := sources.Runtime(ctx, common.RuntimePontusxdev)
if err1 != nil {
return nil, err1
}
return evmcontractcode.NewAnalyzer(common.RuntimePontusxdev, cfg.Analyzers.PontusxdevContractCode.ItemBasedAnalyzerConfig, sourceClient, dbClient, logger)
})
}
if cfg.Analyzers.EmeraldContractVerifier != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagEmerald, func() (A, error) {
return evmverifier.NewAnalyzer(cfg.Source.ChainName, common.RuntimeEmerald, cfg.Analyzers.EmeraldContractVerifier.ItemBasedAnalyzerConfig, cfg.Analyzers.EmeraldContractVerifier.SourcifyServerUrl, dbClient, logger)
Expand All @@ -521,6 +574,11 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return evmverifier.NewAnalyzer(cfg.Source.ChainName, common.RuntimePontusx, cfg.Analyzers.PontusxContractVerifier.ItemBasedAnalyzerConfig, cfg.Analyzers.PontusxContractVerifier.SourcifyServerUrl, dbClient, logger)
})
}
if cfg.Analyzers.PontusxdevContractVerifier != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
return evmverifier.NewAnalyzer(cfg.Source.ChainName, common.RuntimePontusxdev, cfg.Analyzers.PontusxdevContractVerifier.ItemBasedAnalyzerConfig, cfg.Analyzers.PontusxdevContractVerifier.SourcifyServerUrl, dbClient, logger)
})
}
if cfg.Analyzers.EmeraldAbi != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagEmerald, func() (A, error) {
return evmabibackfill.NewAnalyzer(common.RuntimeEmerald, cfg.Analyzers.EmeraldAbi.ItemBasedAnalyzerConfig, dbClient, logger)
Expand All @@ -536,6 +594,11 @@ func NewService(cfg *config.AnalysisConfig) (*Service, error) { //nolint:gocyclo
return evmabibackfill.NewAnalyzer(common.RuntimePontusx, cfg.Analyzers.PontusxAbi.ItemBasedAnalyzerConfig, dbClient, logger)
})
}
if cfg.Analyzers.PontusxdevAbi != nil {
analyzers, err = addAnalyzer(analyzers, err, syncTagPontusxdev, func() (A, error) {
return evmabibackfill.NewAnalyzer(common.RuntimePontusxdev, cfg.Analyzers.PontusxdevAbi.ItemBasedAnalyzerConfig, dbClient, logger)
})
}
if cfg.Analyzers.MetadataRegistry != nil {
analyzers, err = addAnalyzer(analyzers, err, "" /*syncTag*/, func() (A, error) {
return metadata_registry.NewAnalyzer(cfg.Analyzers.MetadataRegistry.ItemBasedAnalyzerConfig, dbClient, logger)
Expand Down
2 changes: 1 addition & 1 deletion cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func NewService(cfg *config.ServerConfig) (*Service, error) {
var networkConfig *sdkConfig.Network
if cfg.Source != nil {
networkConfig = cfg.Source.SDKNetwork()
apiRuntimes := []common.Runtime{common.RuntimeEmerald, common.RuntimeSapphire, common.RuntimePontusx}
apiRuntimes := []common.Runtime{common.RuntimeEmerald, common.RuntimeSapphire, common.RuntimePontusx, common.RuntimePontusxdev}
for _, runtime := range apiRuntimes {
client, err2 := source.NewRuntimeClient(ctx, cfg.Source, runtime)
if err2 != nil {
Expand Down
20 changes: 11 additions & 9 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,23 @@ const (
type Layer string

const (
LayerConsensus Layer = "consensus"
LayerEmerald Layer = "emerald"
LayerCipher Layer = "cipher"
LayerSapphire Layer = "sapphire"
LayerPontusx Layer = "pontusx"
LayerConsensus Layer = "consensus"
LayerEmerald Layer = "emerald"
LayerCipher Layer = "cipher"
LayerSapphire Layer = "sapphire"
LayerPontusx Layer = "pontusx"
LayerPontusxdev Layer = "pontusxdev"
)

// Runtime is an identifier for a runtime on the Oasis Network.
type Runtime string

const (
RuntimeEmerald Runtime = "emerald"
RuntimeCipher Runtime = "cipher"
RuntimeSapphire Runtime = "sapphire"
RuntimePontusx Runtime = "pontusx"
RuntimeEmerald Runtime = "emerald"
RuntimeCipher Runtime = "cipher"
RuntimeSapphire Runtime = "sapphire"
RuntimePontusx Runtime = "pontusx"
RuntimePontusxdev Runtime = "pontusxdev"
)

type CallFormat string
Expand Down
55 changes: 31 additions & 24 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,37 @@ func (cfg *AnalysisConfig) Validate() error {
}

type AnalyzersList struct {
Consensus *BlockBasedAnalyzerConfig `koanf:"consensus"`
Emerald *BlockBasedAnalyzerConfig `koanf:"emerald"`
Sapphire *BlockBasedAnalyzerConfig `koanf:"sapphire"`
Pontusx *BlockBasedAnalyzerConfig `koanf:"pontusx"`
Cipher *BlockBasedAnalyzerConfig `koanf:"cipher"`

EmeraldEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_emerald"`
SapphireEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_sapphire"`
PontusxEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_pontusx"`
EmeraldEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_emerald"`
SapphireEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_sapphire"`
PontusxEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_pontusx"`
EmeraldEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_emerald"`
SapphireEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_sapphire"`
PontusxEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_pontusx"`
EmeraldContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_emerald"`
SapphireContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_sapphire"`
PontusxContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_pontusx"`
EmeraldContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_emerald"`
SapphireContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_sapphire"`
PontusxContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_pontusx"`
EmeraldAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_emerald"`
SapphireAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_sapphire"`
PontusxAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_pontusx"`
Consensus *BlockBasedAnalyzerConfig `koanf:"consensus"`
Emerald *BlockBasedAnalyzerConfig `koanf:"emerald"`
Sapphire *BlockBasedAnalyzerConfig `koanf:"sapphire"`
Pontusx *BlockBasedAnalyzerConfig `koanf:"pontusx"`
Pontusxdev *BlockBasedAnalyzerConfig `koanf:"pontusxdev"`
Cipher *BlockBasedAnalyzerConfig `koanf:"cipher"`

EmeraldEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_emerald"`
SapphireEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_sapphire"`
PontusxEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_pontusx"`
PontusxdevEvmTokens *EvmTokensAnalyzerConfig `koanf:"evm_tokens_pontusxdev"`
EmeraldEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_emerald"`
SapphireEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_sapphire"`
PontusxEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_pontusx"`
PontusxdevEvmNfts *EvmTokensAnalyzerConfig `koanf:"evm_nfts_pontusxdev"`
EmeraldEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_emerald"`
SapphireEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_sapphire"`
PontusxEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_pontusx"`
PontusxdevEvmTokenBalances *EvmTokensAnalyzerConfig `koanf:"evm_token_balances_pontusxdev"`
EmeraldContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_emerald"`
SapphireContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_sapphire"`
PontusxContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_pontusx"`
PontusxdevContractCode *EvmContractCodeAnalyzerConfig `koanf:"evm_contract_code_pontusxdev"`
EmeraldContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_emerald"`
SapphireContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_sapphire"`
PontusxContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_pontusx"`
PontusxdevContractVerifier *EVMContractVerifierConfig `koanf:"evm_contract_verifier_pontusxdev"`
EmeraldAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_emerald"`
SapphireAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_sapphire"`
PontusxAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_pontusx"`
PontusxdevAbi *EvmAbiAnalyzerConfig `koanf:"evm_abi_pontusxdev"`

MetadataRegistry *MetadataRegistryConfig `koanf:"metadata_registry"`
NodeStats *NodeStatsConfig `koanf:"node_stats"`
Expand Down
9 changes: 5 additions & 4 deletions config/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ var DefaultChains = map[common.ChainName]*History{
GenesisHeight: 17751681,
ChainContext: "0b91b8e4e44b2003a7c5e23ddadb5e14ef5345c0ebcb3ddcae07fa2f244cab76",
RuntimeStartRounds: map[common.Runtime]uint64{
common.RuntimeCipher: 1730319,
common.RuntimeEmerald: 2627790,
common.RuntimeSapphire: 2995927,
common.RuntimePontusx: 0,
common.RuntimeCipher: 1730319,
common.RuntimeEmerald: 2627790,
common.RuntimeSapphire: 2995927,
common.RuntimePontusx: 0,
common.RuntimePontusxdev: 0,
},
},
{
Expand Down
5 changes: 0 additions & 5 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ func translateTokenType(tokenType common.TokenType) apiTypes.EvmTokenType {

// runtimeNameToID returns the runtime ID for the given network and runtime name.
func runtimeNameToID(chainName common.ChainName, name common.Runtime) (string, error) {
// XXX Remove once https://github.com/oasisprotocol/oasis-sdk/pull/1638 is merged.
if name == common.RuntimePontusx {
return "0000000000000000000000000000000000000000000000004febe52eb412b421", nil
}

network, exists := oasisConfig.DefaultNetworks.All[string(chainName)]
if !exists {
return "", fmt.Errorf("unknown network: %s", chainName)
Expand Down
5 changes: 5 additions & 0 deletions storage/migrations/14_pontusxdev.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TYPE public.runtime ADD VALUE 'pontusxdev';

COMMIT;

0 comments on commit 61844ef

Please sign in to comment.