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
+1 -1
View File
@@ -35,7 +35,7 @@ func main() {
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())
lastBlockNumber := blockchain.LastBlock().Int64()
+1 -1
View File
@@ -15,7 +15,7 @@ func main() {
startingBlockNumber := flag.Int("starting-number", -1, "First block to fill from")
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())
numberOfBlocksCreated := history.PopulateMissingBlocks(blockchain, repository, int64(*startingBlockNumber))
fmt.Printf("Populated %d blocks", numberOfBlocksCreated)
+19 -15
View File
@@ -1,30 +1,34 @@
package main
import (
"fmt"
"flag"
"time"
"os"
"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/observers"
"github.com/8thlight/vulcanizedb/pkg/history"
)
const (
pollingInterval = 7 * time.Second
)
func main() {
ticker := time.NewTicker(pollingInterval)
defer ticker.Stop()
environment := flag.String("environment", "", "Environment name")
flag.Parse()
config := cmd.LoadConfig(*environment)
fmt.Printf("Creating Geth Blockchain to: %s\n", config.Client.IPCPath)
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
listener := blockchain_listener.NewBlockchainListener(
blockchain,
[]core.BlockchainObserver{
observers.BlockchainLoggingObserver{},
observers.NewBlockchainDbObserver(repository),
},
)
listener.Start()
validator := history.NewBlockValidator(blockchain, repository, 15)
for range ticker.C {
window := validator.ValidateBlocks()
validator.Log(os.Stdout, window)
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ func main() {
_blockNumber := flag.Int64("block-number", -1, "Block number of summary")
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())
blockNumber := cmd.RequestedBlockNumber(_blockNumber)
+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)
}
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ func main() {
contractAbiString := cmd.GetAbi(*abiFilepath, *contractHash)
config := cmd.LoadConfig(*environment)
blockchain := geth.NewGethBlockchain(config.Client.IPCPath)
blockchain := geth.NewBlockchain(config.Client.IPCPath)
repository := cmd.LoadPostgres(config.Database, blockchain.Node())
watchedContract := core.Contract{
Abi: contractAbiString,