05186634bd
- Only syncs block headers (excludes block bodies, transactions, receipts, and logs) - Modifies validation window to include the most recent block - Isolates validation window to the variable defined in the cmd directory (blocks have a separate variable defined in the block_repository for determining when to set a block as final)
42 lines
943 B
Go
42 lines
943 B
Go
package history
|
|
|
|
import (
|
|
"github.com/vulcanize/vulcanizedb/pkg/core"
|
|
"io"
|
|
"text/template"
|
|
)
|
|
|
|
const WindowTemplate = `Validating Blocks
|
|
|{{.LowerBound}}|-- Validation Window --|{{.UpperBound}}| ({{.UpperBound}}:HEAD)
|
|
|
|
`
|
|
|
|
var ParsedWindowTemplate = *template.Must(template.New("window").Parse(WindowTemplate))
|
|
|
|
type ValidationWindow struct {
|
|
LowerBound int64
|
|
UpperBound int64
|
|
}
|
|
|
|
func (window ValidationWindow) Size() int {
|
|
return int(window.UpperBound - window.LowerBound)
|
|
}
|
|
|
|
func MakeValidationWindow(blockchain core.Blockchain, windowSize int) ValidationWindow {
|
|
upperBound := blockchain.LastBlock().Int64()
|
|
lowerBound := upperBound - int64(windowSize)
|
|
return ValidationWindow{lowerBound, upperBound}
|
|
}
|
|
|
|
func MakeRange(min, max int64) []int64 {
|
|
a := make([]int64, max-min+1)
|
|
for i := range a {
|
|
a[i] = min + int64(i)
|
|
}
|
|
return a
|
|
}
|
|
|
|
func (window ValidationWindow) Log(out io.Writer) {
|
|
ParsedWindowTemplate.Execute(out, window)
|
|
}
|