kopia lustrzana https://github.com/bugout-dev/moonstream
Blockchain flag
rodzic
4085d11226
commit
e8ae125dd1
|
@ -28,6 +28,10 @@ func (cb *CorruptBlocks) registerCorruptBlock(number uint64, source, description
|
|||
})
|
||||
}
|
||||
|
||||
func add(blockchain string, start, end uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Return range of block hashes with transaction hashes from blockchain
|
||||
func show(start, end uint64) error {
|
||||
for i := start; i <= end; i++ {
|
||||
|
@ -51,7 +55,7 @@ func show(start, end uint64) error {
|
|||
}
|
||||
|
||||
// Run verification flow of blockchain with database data
|
||||
func verify(start, end uint64) error {
|
||||
func verify(blockchain string, start, end uint64) error {
|
||||
var cnt uint64 // Counter until report formed and sent to Humbug
|
||||
|
||||
for i := start; i < end; i++ {
|
||||
|
@ -63,7 +67,7 @@ func verify(start, end uint64) error {
|
|||
continue
|
||||
}
|
||||
|
||||
dbBlock, err := localConnections.getDatabaseBlockTxs(header.Hash().String())
|
||||
dbBlock, err := localConnections.getDatabaseBlockTxs(blockchain, header.Hash().String())
|
||||
|
||||
if err != nil {
|
||||
description := fmt.Sprintf("Unable to get block: %d, err: %v", i, err)
|
||||
|
@ -101,7 +105,7 @@ func verify(start, end uint64) error {
|
|||
if cnt >= configs.BLOCK_RANGE_REPORT {
|
||||
err := humbugReporter.submitReport(start, end)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to send humbug report: %v", err)
|
||||
return fmt.Errorf("Unable to send humbug report: %v", err)
|
||||
}
|
||||
cnt = 0
|
||||
}
|
||||
|
@ -109,7 +113,7 @@ func verify(start, end uint64) error {
|
|||
|
||||
err := humbugReporter.submitReport(start, end)
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to send humbug report: %v", err)
|
||||
return fmt.Errorf("Unable to send humbug report: %v", err)
|
||||
}
|
||||
fmt.Println("")
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
BlockchainFlag = cli.StringFlag{
|
||||
Name: "blockchain",
|
||||
Usage: `Which blockchain to crawl ("ethereum", "polygon")`,
|
||||
}
|
||||
DataDirFlag = cli.StringFlag{
|
||||
Name: "datadir",
|
||||
Usage: "Data directory for the databases and keystore",
|
||||
|
@ -27,6 +31,7 @@ var (
|
|||
)
|
||||
|
||||
// Parse start and end blocks from command line input
|
||||
// TODO(kompotkot): Re-write to work via channel in goroutines
|
||||
func startEndBlock(ctx *cli.Context) (uint64, uint64, error) {
|
||||
start, err := strconv.ParseUint(ctx.Args().Get(0), 10, 32)
|
||||
if err != nil {
|
||||
|
@ -44,53 +49,9 @@ func processAddCommand(ctx *cli.Context) error {
|
|||
if ctx.NArg() != 2 {
|
||||
return fmt.Errorf("Required arguments: %v", ctx.Command.ArgsUsage)
|
||||
}
|
||||
|
||||
start, end, err := startEndBlock(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse block range: %v", err)
|
||||
}
|
||||
|
||||
err = setLocalChain(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to set blockchain: %v", err)
|
||||
}
|
||||
defer localConnections.Stack.Close()
|
||||
defer localConnections.ChainDB.Close()
|
||||
|
||||
show(start, end)
|
||||
|
||||
localConnections.Chain.Stop()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processShowCommand(ctx *cli.Context) error {
|
||||
if ctx.NArg() != 2 {
|
||||
return fmt.Errorf("Required arguments: %v", ctx.Command.ArgsUsage)
|
||||
}
|
||||
|
||||
start, end, err := startEndBlock(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse block range: %v", err)
|
||||
}
|
||||
|
||||
err = setLocalChain(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to set blockchain: %v", err)
|
||||
}
|
||||
defer localConnections.Stack.Close()
|
||||
defer localConnections.ChainDB.Close()
|
||||
|
||||
show(start, end)
|
||||
|
||||
localConnections.Chain.Stop()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processVerifyCommand(ctx *cli.Context) error {
|
||||
if ctx.NArg() != 2 {
|
||||
return fmt.Errorf("Required arguments: %v", ctx.Command.ArgsUsage)
|
||||
blockchain := ctx.GlobalString(BlockchainFlag.Name)
|
||||
if blockchain != "ethereum" && blockchain != "polygon" {
|
||||
return fmt.Errorf("Unsupported blockchain provided")
|
||||
}
|
||||
|
||||
start, end, err := startEndBlock(ctx)
|
||||
|
@ -110,7 +71,77 @@ func processVerifyCommand(ctx *cli.Context) error {
|
|||
return fmt.Errorf("Unable to set database connection: %v", err)
|
||||
}
|
||||
|
||||
verify(start, end)
|
||||
err = add(blockchain, start, end)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error occurred due add acction: %v", err)
|
||||
}
|
||||
|
||||
localConnections.Chain.Stop()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processShowCommand(ctx *cli.Context) error {
|
||||
if ctx.NArg() != 2 {
|
||||
return fmt.Errorf("Required arguments: %v", ctx.Command.ArgsUsage)
|
||||
}
|
||||
blockchain := ctx.GlobalString(BlockchainFlag.Name)
|
||||
if blockchain != "ethereum" && blockchain != "polygon" {
|
||||
return fmt.Errorf("Unsupported blockchain provided")
|
||||
}
|
||||
|
||||
start, end, err := startEndBlock(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse block range: %v", err)
|
||||
}
|
||||
|
||||
err = setLocalChain(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to set blockchain: %v", err)
|
||||
}
|
||||
defer localConnections.Stack.Close()
|
||||
defer localConnections.ChainDB.Close()
|
||||
|
||||
err = show(start, end)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error occurred due show acction: %v", err)
|
||||
}
|
||||
|
||||
localConnections.Chain.Stop()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func processVerifyCommand(ctx *cli.Context) error {
|
||||
if ctx.NArg() != 2 {
|
||||
return fmt.Errorf("Required arguments: %v", ctx.Command.ArgsUsage)
|
||||
}
|
||||
blockchain := ctx.GlobalString(BlockchainFlag.Name)
|
||||
if blockchain != "ethereum" && blockchain != "polygon" {
|
||||
return fmt.Errorf("Unsupported blockchain provided")
|
||||
}
|
||||
|
||||
start, end, err := startEndBlock(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to parse block range: %v", err)
|
||||
}
|
||||
|
||||
err = setLocalChain(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to set blockchain: %v", err)
|
||||
}
|
||||
defer localConnections.Stack.Close()
|
||||
defer localConnections.ChainDB.Close()
|
||||
|
||||
err = setDatabase()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to set database connection: %v", err)
|
||||
}
|
||||
|
||||
err = verify(blockchain, start, end)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error occurred due verify acction: %v", err)
|
||||
}
|
||||
|
||||
localConnections.Chain.Stop()
|
||||
|
||||
|
@ -124,9 +155,11 @@ func LDBCLI() {
|
|||
app.Email = "engineering@bugout.dev"
|
||||
app.Usage = "blockchain ldb extractor command line interface"
|
||||
app.Flags = []cli.Flag{
|
||||
BlockchainFlag,
|
||||
DataDirFlag,
|
||||
GCModeFlag,
|
||||
}
|
||||
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "add",
|
||||
|
@ -135,6 +168,7 @@ func LDBCLI() {
|
|||
Usage: "Add new blocks with transactions to database",
|
||||
Description: "This command request blocks from blockchain and adds to database.",
|
||||
Flags: []cli.Flag{
|
||||
BlockchainFlag,
|
||||
DataDirFlag,
|
||||
GCModeFlag,
|
||||
},
|
||||
|
@ -146,6 +180,7 @@ func LDBCLI() {
|
|||
Usage: "Show block with transactions",
|
||||
Description: "This command print out requested blocks.",
|
||||
Flags: []cli.Flag{
|
||||
BlockchainFlag,
|
||||
DataDirFlag,
|
||||
GCModeFlag,
|
||||
},
|
||||
|
@ -157,6 +192,7 @@ func LDBCLI() {
|
|||
Usage: "Verify blocks with transactions at database",
|
||||
Description: "This command compare blocks in database and in blockchain for difference.",
|
||||
Flags: []cli.Flag{
|
||||
BlockchainFlag,
|
||||
DataDirFlag,
|
||||
GCModeFlag,
|
||||
},
|
||||
|
|
|
@ -94,17 +94,25 @@ func (lc *LocalConnections) getChainTxs(headerHash common.Hash, number uint64) [
|
|||
}
|
||||
|
||||
// Retrive block with transactions from database
|
||||
func (lc *LocalConnections) getDatabaseBlockTxs(headerHash string) (LightBlock, error) {
|
||||
func (lc *LocalConnections) getDatabaseBlockTxs(blockchain, headerHash string) (LightBlock, error) {
|
||||
var lBlock LightBlock
|
||||
var txs []LightTransaction
|
||||
query := fmt.Sprintf(
|
||||
`SELECT
|
||||
ethereum_blocks.hash,
|
||||
ethereum_blocks.block_number,
|
||||
ethereum_transactions.hash
|
||||
FROM ethereum_blocks
|
||||
LEFT JOIN ethereum_transactions ON ethereum_blocks.block_number = ethereum_transactions.block_number
|
||||
WHERE ethereum_blocks.hash = '%s';`,
|
||||
%s_blocks.hash,
|
||||
%s_blocks.block_number,
|
||||
%s_transactions.hash
|
||||
FROM %s_blocks
|
||||
LEFT JOIN %s_transactions ON %s_blocks.block_number = %s_transactions.block_number
|
||||
WHERE %s_blocks.hash = '%s';`,
|
||||
blockchain,
|
||||
blockchain,
|
||||
blockchain,
|
||||
blockchain,
|
||||
blockchain,
|
||||
blockchain,
|
||||
blockchain,
|
||||
blockchain,
|
||||
headerHash,
|
||||
)
|
||||
rows, err := lc.Database.Query(query)
|
||||
|
|
Ładowanie…
Reference in New Issue