Skip to content

Commit

Permalink
Merge pull request #1668 from oasisprotocol/pro-wh/feature/tscore
Browse files Browse the repository at this point in the history
ts-web/core: 23.x updates
  • Loading branch information
pro-wh authored Apr 5, 2024
2 parents 5bec25f + 3260afd commit 1d141bc
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
18 changes: 9 additions & 9 deletions client-sdk/ts-web/core/reflect-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ var skipMethods = map[string]bool{
}
var skipMethodsConsulted = map[string]bool{}

func visitClientWithPrefix(client *clientCode, t reflect.Type, prefix string) {
func visitClientWithService(client *clientCode, t reflect.Type, service string, methodPrefix string) {
_, _ = fmt.Fprintf(os.Stderr, "visiting client %v\n", t)
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
Expand Down Expand Up @@ -650,17 +650,17 @@ func visitClientWithPrefix(client *clientCode, t reflect.Type, prefix string) {
outRef = "void"
}
methodDoc := renderDocComment(getMethodDoc(t, m.Name), " ")
lowerPrefix := strings.ToLower(prefix[:1]) + prefix[1:]
client.methodDescriptors += fmt.Sprintf("const methodDescriptor%s%s = createMethodDescriptor%s<%s, %s>('%s', '%s');\n", prefix, m.Name, descriptorKind, inRef, outRef, prefix, m.Name)
client.methods += fmt.Sprintf("%s %s%s(%s) { return this.call%s(methodDescriptor%s%s, %s); }\n", methodDoc, lowerPrefix, m.Name, inParam, descriptorKind, prefix, m.Name, inArg)
lowerService := strings.ToLower(service[:1]) + service[1:]
client.methodDescriptors += fmt.Sprintf("const methodDescriptor%s%s%s = createMethodDescriptor%s<%s, %s>('%s', '%s%s');\n", service, methodPrefix, m.Name, descriptorKind, inRef, outRef, service, methodPrefix, m.Name)
client.methods += fmt.Sprintf("%s %s%s%s(%s) { return this.call%s(methodDescriptor%s%s%s, %s); }\n", methodDoc, lowerService, methodPrefix, m.Name, inParam, descriptorKind, service, methodPrefix, m.Name, inArg)
client.methods += "\n"
}
client.methodDescriptors += "\n"
}

func visitClient(client *clientCode, t reflect.Type) {
prefix := getPrefix(t)
visitClientWithPrefix(client, t, prefix)
visitClientWithService(client, t, prefix, "")
}

func write() {
Expand Down Expand Up @@ -695,12 +695,12 @@ func main() {
visitClient(&internal, reflect.TypeOf((*roothash.Backend)(nil)).Elem())
visitClient(&internal, reflect.TypeOf((*governance.Backend)(nil)).Elem())
visitClient(&internal, reflect.TypeOf((*storage.Backend)(nil)).Elem())
visitClientWithPrefix(&internal, reflect.TypeOf((*workerStorage.StorageWorker)(nil)).Elem(), "StorageWorker")
visitClientWithService(&internal, reflect.TypeOf((*workerStorage.StorageWorker)(nil)).Elem(), "StorageWorker", "")
visitClient(&internal, reflect.TypeOf((*runtimeClient.RuntimeClient)(nil)).Elem())
visitClient(&internal, reflect.TypeOf((*consensus.ClientBackend)(nil)).Elem())
visitClientWithPrefix(&internal, reflect.TypeOf((*syncer.ReadSyncer)(nil)).Elem(), "ConsensusState") // this doesn't work right
visitClientWithPrefix(&internal, reflect.TypeOf((*control.NodeController)(nil)).Elem(), "NodeController")
visitClientWithPrefix(&internal, reflect.TypeOf((*control.DebugController)(nil)).Elem(), "DebugController")
visitClientWithService(&internal, reflect.TypeOf((*syncer.ReadSyncer)(nil)).Elem(), "Consensus", "State")
visitClientWithService(&internal, reflect.TypeOf((*control.NodeController)(nil)).Elem(), "NodeController", "")
visitClientWithService(&internal, reflect.TypeOf((*control.DebugController)(nil)).Elem(), "DebugController", "")

_, _ = fmt.Fprintf(os.Stderr, "visiting transaction body types\n")
registeredMethods.Range(func(name, bodyType interface{}) bool {
Expand Down
32 changes: 29 additions & 3 deletions client-sdk/ts-web/core/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Code below not generated by reflect-go.
import * as grpcWeb from 'grpc-web';

import * as proto from '../proto';
Expand Down Expand Up @@ -133,6 +134,7 @@ End of invocation stack`;
);
}
}
// Code above not generated by reflect-go.

const methodDescriptorBeaconConsensusParameters = createMethodDescriptorUnary<
types.longnum,
Expand Down Expand Up @@ -407,6 +409,14 @@ const methodDescriptorRootHashGetLatestBlock = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashBlock
>('RootHash', 'GetLatestBlock');
const methodDescriptorRootHashGetPastRoundRoots = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
Map<types.longnum, types.RootHashRoundRoots>
>('RootHash', 'GetPastRoundRoots');
const methodDescriptorRootHashGetRoundRoots = createMethodDescriptorUnary<
types.RootHashRoundRootsRequest,
types.RootHashRoundRoots
>('RootHash', 'GetRoundRoots');
const methodDescriptorRootHashGetRuntimeState = createMethodDescriptorUnary<
types.RootHashRuntimeRequest,
types.RootHashRuntimeState
Expand All @@ -424,7 +434,7 @@ const methodDescriptorRootHashWatchEvents = createMethodDescriptorServerStreamin
types.RootHashEvent
>('RootHash', 'WatchEvents');
const methodDescriptorRootHashWatchExecutorCommitments = createMethodDescriptorServerStreaming<
void,
Uint8Array,
types.RootHashExecutorCommitment
>('RootHash', 'WatchExecutorCommitments');

Expand Down Expand Up @@ -685,9 +695,11 @@ const methodDescriptorDebugControllerWaitNodesRegistered = createMethodDescripto
>('DebugController', 'WaitNodesRegistered');

export class NodeInternal extends GRPCWrapper {
// Code below not generated by reflect-go.
constructor(base: string) {
super(base);
}
// Code above not generated by reflect-go.

/**
* ConsensusParameters returns the beacon consensus parameters.
Expand Down Expand Up @@ -1214,6 +1226,20 @@ export class NodeInternal extends GRPCWrapper {
return this.callUnary(methodDescriptorRootHashGetLatestBlock, request);
}

/**
* GetPastRoundRoots returns the stored past state and I/O roots for the given runtime.
*/
rootHashGetPastRoundRoots(request: types.RootHashRuntimeRequest) {
return this.callUnary(methodDescriptorRootHashGetPastRoundRoots, request);
}

/**
* GetPastRoundRoots returns the stored state and I/O roots for the given runtime and round.
*/
rootHashGetRoundRoots(request: types.RootHashRoundRootsRequest) {
return this.callUnary(methodDescriptorRootHashGetRoundRoots, request);
}

/**
* GetRuntimeState returns the given runtime's state.
*/
Expand Down Expand Up @@ -1254,10 +1280,10 @@ export class NodeInternal extends GRPCWrapper {
* Note that these commitments may not have been processed by consensus, commitments may be
* received in any order and duplicates are possible.
*/
rootHashWatchExecutorCommitments() {
rootHashWatchExecutorCommitments(runtimeID: Uint8Array) {
return this.callServerStreaming(
methodDescriptorRootHashWatchExecutorCommitments,
undefined,
runtimeID,
);
}

Expand Down
35 changes: 33 additions & 2 deletions client-sdk/ts-web/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Code below not generated by reflect-go.
export type NotModeled = {[key: string]: unknown};

/**
Expand All @@ -6,6 +7,7 @@ export type NotModeled = {[key: string]: unknown};
* lost in serialization; apologies), so you should perhaps cast to bigint for consistency.
*/
export type longnum = number | bigint;
// Code above not generated by reflect-go.

/**
* ConsensusParameters are the beacon consensus parameters.
Expand Down Expand Up @@ -2207,6 +2209,10 @@ export interface RootHashEvidence {
* ExecutionDiscrepancyDetectedEvent is an execute discrepancy detected event.
*/
export interface RootHashExecutionDiscrepancyDetectedEvent {
/**
* Round is the round in which the discrepancy was detected.
*/
round: longnum;
/**
* Rank is the rank of the transaction scheduler.
*/
Expand Down Expand Up @@ -2468,15 +2474,15 @@ export interface RootHashLivenessStatistics {
good_rounds: longnum[];
/**
* FinalizedProposals is a list that records the number of finalized rounds when a node
* acted as a proposer.
* acted as a proposer with the highest rank.
*
* The list is ordered according to the committee arrangement (i.e., the counter at index i
* holds the value for the node at index i in the committee).
*/
finalized_proposals: longnum[];
/**
* MissedProposals is a list that records the number of failed rounds when a node
* acted as a proposer.
* acted as a proposer with the highest rank.
*
* The list is ordered according to the committee arrangement (i.e., the counter at index i
* holds the value for the node at index i in the committee).
Expand Down Expand Up @@ -2599,6 +2605,21 @@ export interface RootHashRoundResults {
bad_compute_entities?: Uint8Array[];
}

/**
* RoundRoots holds the per-round state and I/O roots that are stored in
* consensus state.
*/
export type RootHashRoundRoots = [StateRoot: Uint8Array, IORoot: Uint8Array];

/**
* RoundRootsRequest is a request for a specific runtime and round's state and I/O roots.
*/
export interface RootHashRoundRootsRequest {
runtime_id: Uint8Array;
height: longnum;
round: longnum;
}

/**
* RuntimeRequest is a generic roothash get request for a specific runtime.
*/
Expand Down Expand Up @@ -3788,6 +3809,16 @@ export interface WorkerCommonLivenessStatus {
* LiveRounds is the number of rounds in which the node positively contributed.
*/
live_rounds: longnum;
/**
* FinalizedProposals is the number of finalized rounds when a node acted as a proposer
* with the highest rank.
*/
finalized_proposals: longnum;
/**
* MissedProposals is the number of failed rounds when a node acted as a proposer
* with the highest rank.
*/
missed_proposals: longnum;
}

/**
Expand Down

0 comments on commit 1d141bc

Please sign in to comment.