newRunTime returns a new sql-chain runtime instance with the specified config.
(ctx context.Context, c *Config)
| 97 | |
| 98 | // newRunTime returns a new sql-chain runtime instance with the specified config. |
| 99 | func 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 | |
| 139 | func (r *runtime) setGenesis(b *types.Block) { |
| 140 | r.chainInitTime = b.Timestamp() |
no test coverage detected