2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
2019-03-12 15:46:42 +00:00
|
|
|
// Copyright © 2019 Vulcanize
|
2018-11-07 21:50:43 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-07-17 21:23:07 +00:00
|
|
|
package history
|
|
|
|
|
|
|
|
import (
|
2019-01-31 14:55:28 +00:00
|
|
|
"fmt"
|
2019-05-17 04:15:54 +00:00
|
|
|
|
2019-02-14 15:03:57 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-07-17 21:23:07 +00:00
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ValidationWindow struct {
|
|
|
|
LowerBound int64
|
|
|
|
UpperBound int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (window ValidationWindow) Size() int {
|
|
|
|
return int(window.UpperBound - window.LowerBound)
|
|
|
|
}
|
|
|
|
|
2019-02-14 15:03:57 +00:00
|
|
|
func MakeValidationWindow(blockchain core.BlockChain, windowSize int) (ValidationWindow, error) {
|
|
|
|
upperBound, err := blockchain.LastBlock()
|
|
|
|
if err != nil {
|
|
|
|
log.Error("MakeValidationWindow: error getting LastBlock: ", err)
|
|
|
|
return ValidationWindow{}, err
|
|
|
|
}
|
|
|
|
lowerBound := upperBound.Int64() - int64(windowSize)
|
|
|
|
return ValidationWindow{lowerBound, upperBound.Int64()}, nil
|
2018-07-17 21:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func MakeRange(min, max int64) []int64 {
|
|
|
|
a := make([]int64, max-min+1)
|
|
|
|
for i := range a {
|
|
|
|
a[i] = min + int64(i)
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2019-01-31 14:55:28 +00:00
|
|
|
func (window ValidationWindow) GetString() string {
|
2019-06-26 00:24:56 +00:00
|
|
|
return fmt.Sprintf("Validating Blocks |%v|-- Validation Window --|%v|",
|
2019-01-31 14:55:28 +00:00
|
|
|
window.LowerBound, window.UpperBound)
|
2018-07-17 21:23:07 +00:00
|
|
|
}
|