MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / newRunTime

Function newRunTime

sqlchain/runtime.go:99–137  ·  view source on GitHub ↗

newRunTime returns a new sql-chain runtime instance with the specified config.

(ctx context.Context, c *Config)

Source from the content-addressed store, hash-verified

97
98// newRunTime returns a new sql-chain runtime instance with the specified config.
99func newRunTime(ctx context.Context, c *Config) (r *runtime) {
100 var cld, ccl = context.WithCancel(ctx)
101 r = &runtime{
102 wg: &sync.WaitGroup{},
103 ctx: cld,
104 cancel: ccl,
105
106 period: c.Period,
107 tick: c.Tick,
108 queryTTL: c.QueryTTL,
109 blockCacheTTL: blockCacheTTLRequired(c),
110 muxService: c.MuxService,
111 peers: c.Peers,
112 server: c.Server,
113 index: func() int32 {
114 if index, found := c.Peers.Find(c.Server); found {
115 return index
116 }
117
118 log.WithFields(log.Fields{
119 "node": c.Server,
120 "peers": c.Peers,
121 }).Warning("could not found server in peers")
122
123 return -1
124 }(),
125 total: int32(len(c.Peers.Servers)),
126 nextTurn: 1,
127 head: &state{},
128 lastBillingHeight: c.LastBillingHeight,
129 offset: time.Duration(0),
130 }
131
132 if c.Genesis != nil {
133 r.setGenesis(c.Genesis)
134 }
135
136 return
137}
138
139func (r *runtime) setGenesis(b *types.Block) {
140 r.chainInitTime = b.Timestamp()

Callers 1

NewChainWithContextFunction · 0.85

Calls 5

WithFieldsFunction · 0.92
blockCacheTTLRequiredFunction · 0.85
FindMethod · 0.80
WarningMethod · 0.80
setGenesisMethod · 0.80

Tested by

no test coverage detected