docs: document transition matrix usage; add example (#25255)

Co-authored-by: Alex | Interchain Labs <alex@djinntek.world>
This commit is contained in:
Marco
2025-08-26 14:39:05 -04:00
committed by GitHub
co-authored by Alex | Interchain Labs
parent b34bd73a76
commit 5f5ca59b0b
2 changed files with 33 additions and 2 deletions
+14 -1
View File
@@ -20,7 +20,20 @@ const (
maxTimePerBlock int64 = 10000
)
// TODO: explain transitional matrix usage
// The transition matrices below control stochastic behavior in the simulation:
//
// - defaultLivenessTransitionMatrix: models validator liveness across three
// states (online, spotty, offline). Each column represents the current state,
// each row represents the next state; entries are integer weights used for
// weighted random selection. Higher weights mean higher probability.
//
// - defaultBlockSizeTransitionMatrix: models block size regimes across three
// states (large range, medium range, zero). Similar column-as-current,
// row-as-next convention applies.
//
// These matrices are fed into CreateTransitionMatrix, which precomputes column
// totals for efficient sampling. During simulation, NextState(r, i) is called
// with a deterministic RNG r and current state i to obtain the next state.
var (
// Currently there are 3 different liveness types,
// fully online, spotty connection, offline.
+19 -1
View File
@@ -20,7 +20,25 @@ type TransitionMatrix struct {
}
// CreateTransitionMatrix creates a transition matrix from the provided weights.
// TODO: Provide example usage
//
// Example:
//
// weights := [][]int{
// // From state 0 to states 0,1,2
// {90, 10, 0},
// // From state 1 to states 0,1,2
// {20, 70, 10},
// // From state 2 to states 0,1,2
// {5, 15, 80},
// }
// tm, err := CreateTransitionMatrix(weights)
// if err != nil {
// // handle error
// }
//
// // NextState picks the next state from current state i.
// // r should be a deterministic *rand.Rand when used in simulations.
// // next := tm.NextState(r, i)
func CreateTransitionMatrix(weights [][]int) (simulation.TransitionMatrix, error) {
n := len(weights)
for i := range n {