Skip to content

Commit

Permalink
Get bootstrapped rollups genesis info from RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Mar 17, 2024
1 parent 90581c9 commit 6abef5d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions Tzkt.Sync/Protocols/Abstract/IRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IRpc
Task<JsonElement> GetDelegateAsync(int level, string address);
Task<JsonElement> GetStakeDistribution(int block, int cycle);
Task<JsonElement> GetExpectedIssuance(int level);
Task<JsonElement> GetSmartRollupGenesisInfo(int level, string address);
#endregion

#region diagnostics
Expand Down
3 changes: 3 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Genesis/Rpc/Rpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public Task<JsonElement> GetStakeDistribution(int block, int cycle)

public Task<JsonElement> GetExpectedIssuance(int level)
=> throw new InvalidOperationException();

public Task<JsonElement> GetSmartRollupGenesisInfo(int level, string address)
=> throw new InvalidOperationException();
#endregion

#region diagnostics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ protected virtual async Task<List<Account>> BootstrapAccounts(Protocol protocol,
#region bootstrap smart rollups
foreach (var (address, pvmKind) in bootstrapSmartRollups)
{
var genesisInfo = await Proto.Rpc.GetSmartRollupGenesisInfo(1, address);

var creator = nullAddress;
var rollup = new SmartRollup()
{
Expand All @@ -237,9 +239,9 @@ protected virtual async Task<List<Account>> BootstrapAccounts(Protocol protocol,
"wasm_2_0_0" => PvmKind.Wasm,
_ => throw new NotImplementedException()
},
GenesisCommitment = "genesis_commitment_hash", // this should be calculated from Machine.install_boot_sector and Machine.state_hash,
LastCommitment = "genesis_commitment_hash", // but that cannot be done on the indexer side, so we set a random string
InboxLevel = 2,
GenesisCommitment = genesisInfo.RequiredString("commitment_hash"),
LastCommitment = genesisInfo.RequiredString("commitment_hash"),
InboxLevel = genesisInfo.RequiredInt32("level"),
TotalStakers = 0,
ActiveStakers = 0,
ExecutedCommitments = 0,
Expand Down
5 changes: 4 additions & 1 deletion Tzkt.Sync/Protocols/Handlers/Proto1/Rpc/Rpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Rpc : IRpc

#region indexer
public virtual Task<JsonElement> GetBlockAsync(int level)
=> Node.GetAsync($"chains/main/blocks/{level}");
=> Node.GetAsync($"chains/main/blocks/{level}?version=0");

public virtual Task<JsonElement> GetBakingRightsAsync(int block, int cycle)
=> Node.GetAsync($"chains/main/blocks/{block}/helpers/baking_rights?cycle={cycle}&max_priority=8&all=true");
Expand All @@ -36,6 +36,9 @@ public virtual Task<JsonElement> GetStakeDistribution(int block, int cycle)

public virtual Task<JsonElement> GetExpectedIssuance(int block)
=> throw new InvalidOperationException();

public virtual Task<JsonElement> GetSmartRollupGenesisInfo(int level, string address)
=> throw new InvalidOperationException();
#endregion

#region diagnostics
Expand Down
3 changes: 3 additions & 0 deletions Tzkt.Sync/Protocols/Handlers/Proto18/Rpc/Rpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public Rpc(TezosNode node) : base(node) { }
public override Task<JsonElement> GetExpectedIssuance(int level)
=> Node.GetAsync($"chains/main/blocks/{level}/context/issuance/expected_issuance");

public override Task<JsonElement> GetSmartRollupGenesisInfo(int level, string address)
=> Node.GetAsync($"chains/main/blocks/{level}/context/smart_rollups/smart_rollup/{address}/genesis_info");

public override Task<JsonElement> GetCurrentStakingBalance(int level, string address)
=> Node.GetAsync($"chains/main/blocks/{level}/context/raw/json/staking_balance/current/{address}");

Expand Down

0 comments on commit 6abef5d

Please sign in to comment.