Fix NewCalculator() to work at first term.
@@ -995,21 +995,33 @@ func (c *Calculator) postWork() (err error) {
const InitBlockHeight = -1
func NewCalculator(back *icstage.Snapshot, reward *icreward.Snapshot, logger log.Logger) *Calculator {
- global, err := back.GetGlobal()
+ var err error
+ var global icstage.Global
+ var startHeight int64
+
+ global, err = back.GetGlobal()
if err != nil {
- logger.Errorf("There is no Global values for calcaultor")
+ logger.Errorf("Failed to get Global values for calculator. %+v", err)
return nil
}
+ if global == nil {
+ // back has no global at first term
+ startHeight = InitBlockHeight
+ } else {
+ startHeight = global.GetStartHeight()
+ }
c := &Calculator{
back: back,
base: reward,
temp: icreward.NewStateFromSnapshot(reward),
log: logger,
global: global,
- startHeight: global.GetStartHeight(),
+ startHeight: startHeight,
stats: newStatistics(),
}
+ if startHeight != InitBlockHeight {
go c.run()
+ }
return c
}
