Remove pubsub and replace w/ polling head of chain (#122)

* Rename geth package structs to not be prefaced with package name

* No longer need to dump schema since Travis uses migrate

* Rearrange history package

* Removed double request for receipt from block rewards

* Remove Listener + Observers and Replace w/ Polling Head

* Potential Short term Issue w/ Infura (ignore these tests for now)
This commit is contained in:
Matt K
2018-01-05 11:55:00 -06:00
committed by GitHub
parent 095cb1e7b7
commit 6decf0b54b
38 changed files with 368 additions and 1034 deletions
+13 -39
View File
@@ -6,71 +6,45 @@ import (
"time"
"os"
"text/template"
"github.com/8thlight/vulcanizedb/cmd"
"github.com/8thlight/vulcanizedb/pkg/blockchain_listener"
"github.com/8thlight/vulcanizedb/pkg/core"
"github.com/8thlight/vulcanizedb/pkg/geth"
"github.com/8thlight/vulcanizedb/pkg/history"
"github.com/8thlight/vulcanizedb/pkg/observers"
"github.com/8thlight/vulcanizedb/pkg/repositories"
)
const windowTemplate = `Validating Existing Blocks
|{{.LowerBound}}|-- Validation Window --|{{.UpperBound}}| {{.MaxBlockNumber}}(HEAD)
`
const (
windowSize = 24
pollingInterval = 10 * time.Second
pollingInterval = 7 * time.Second
)
func createListener(blockchain *geth.GethBlockchain, repository repositories.Postgres) blockchain_listener.BlockchainListener {
listener := blockchain_listener.NewBlockchainListener(
blockchain,
[]core.BlockchainObserver{
observers.BlockchainLoggingObserver{},
observers.NewBlockchainDbObserver(repository),
},
)
return listener
}
func validateBlocks(blockchain *geth.GethBlockchain, repository repositories.Postgres, windowSize int, windowTemplate *template.Template) {
window := history.UpdateBlocksWindow(blockchain, repository, windowSize)
repository.SetBlocksStatus(blockchain.LastBlock().Int64())
windowTemplate.Execute(os.Stdout, window)
func backFillAllBlocks(blockchain core.Blockchain, repository repositories.Postgres, missingBlocksPopulated chan int) {
go func() {
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, repository, 0)
}()
}
func main() {
parsedWindowTemplate := template.Must(template.New("window").Parse(windowTemplate))
ticker := time.NewTicker(pollingInterval)
defer ticker.Stop()
environment := flag.String("environment", "", "Environment name")
flag.Parse()
config := cmd.LoadConfig(*environment)
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
listner := createListener(blockchain, repository)
go listner.Start()
defer listner.Stop()
validator := history.NewBlockValidator(blockchain, repository, 15)
missingBlocksPopulated := make(chan int)
go func() {
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, repository, 0)
}()
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated)
for range ticker.C {
validateBlocks(blockchain, repository, windowSize, parsedWindowTemplate)
for {
select {
case <-ticker.C:
window := validator.ValidateBlocks()
validator.Log(os.Stdout, window)
case <-missingBlocksPopulated:
go func() {
missingBlocksPopulated <- history.PopulateMissingBlocks(blockchain, repository, 0)
}()
default:
go backFillAllBlocks(blockchain, repository, missingBlocksPopulated)
}
}
}