forge

package
v0.1.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2023 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Copyright © 2022 Polygon <engineering@polygon.technology>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var (
	BlockReadEOF = errors.New("no more blocks to read")
)
View Source
var ForgeCmd = &cobra.Command{
	Use:   "forge",
	Short: "A utility for generating blockchain data either for testing or migration",
	Long: `A utility for generating blockchain data either for testing or migration.

Here is an example usage:
  # In this case local host is running a POA Core Archive node.
  polycli dumpblocks http://127.0.0.1:8545 0 100000 --filename poa-core.0.to.100k --dump-receipts=false

  # Even with disabling receipts, edge's eth_getBlockByNumber returns transactions.
  # This needs to be done only if using json mode. Filter them out before forging:
  cat poa-core.0.to.100k | grep '"difficulty"' > poa-core.0.to.100k.blocks

  polycli forge --genesis genesis.json --mode json --blocks poa-core.0.to.100k.blocks --count 99999`,

	RunE: func(cmd *cobra.Command, args []string) error {
		fmt.Println("forge called")
		blockchain, err := NewEdgeBlockchain()
		if err != nil {
			return err
		}

		blockReader, err := OpenBlockReader(inputForge.BlocksFile, inputForge.Mode)
		if err != nil {
			return err
		}

		receiptReader, err := OpenReceiptReader(inputForge.ReceiptsFile, inputForge.Mode)
		if inputForge.IncludeTxFees && err != nil {
			return err
		}

		err = readAllBlocksToChain(blockchain, blockReader, receiptReader)

		return err
	},
	Args: func(cmd *cobra.Command, args []string) error {
		if inputForge.Client != "edge" {
			return fmt.Errorf("the client %s is not supported. Only Edge is supported", inputForge.Client)
		}
		if !slices.Contains([]string{"json", "proto"}, inputForge.Mode) {
			return fmt.Errorf("output format must one of [json, proto]")
		}
		f, err := os.Open(inputForge.GenesisFile)
		if err != nil {
			return fmt.Errorf("unable to open genesis file: %w", err)
		}
		genesisData, err := io.ReadAll(f)
		if err != nil {
			return fmt.Errorf("unable to read genesis file data: %w", err)
		}
		inputForge.GenesisData = genesisData

		return nil
	},
}

forgeCmd represents the forge command

Functions

func GenerateRandomBlock

func GenerateRandomBlock(number uint64) *edgetypes.Block

GenerateRandomBlock in most cases we can use existing blocks and transactions for forgeries and testing, but at some point we might want to generate complete random blocks especially if we want to model state size after 10 - 20 years of operation

func IsEmptyAddress

func IsEmptyAddress(addr []byte) bool

IsEmptyAddress will just check a slice of bytes to check if it's all zeros or not.

func NewEdgeBlockchain

func NewEdgeBlockchain() (*edgeBlockchainHandle, error)

func PolyBlockToEdge

func PolyBlockToEdge(polyBlock rpctypes.PolyBlock) *edgetypes.Block

PolyBlockToEdge will take the generic PolyBlock interface and convert it into an Edge compatible block.

func ReadProtoFromFile

func ReadProtoFromFile(filepath string) ([][]byte, error)

Types

type BlockReader

type BlockReader interface {
	ReadBlock() (rpctypes.PolyBlock, error)
}

func OpenBlockReader

func OpenBlockReader(file string, mode string) (BlockReader, error)

OpenBlockReader returns a block reader object which can be used to read the file. It will return a mode specific block reader.

type JSONBlockReader

type JSONBlockReader struct {
	// contains filtered or unexported fields
}

func (*JSONBlockReader) ReadBlock

func (blockReader *JSONBlockReader) ReadBlock() (rpctypes.PolyBlock, error)

type JSONReceiptReader added in v0.1.17

type JSONReceiptReader struct {
	// contains filtered or unexported fields
}

func (*JSONReceiptReader) ReadReceipt added in v0.1.17

func (receiptsReader *JSONReceiptReader) ReadReceipt() (*rpctypes.RawTxReceipt, error)

type ProtoBlockReader

type ProtoBlockReader struct {
	// contains filtered or unexported fields
}

func (*ProtoBlockReader) ReadBlock

func (blockReader *ProtoBlockReader) ReadBlock() (rpctypes.PolyBlock, error)

type ReceiptReader added in v0.1.17

type ReceiptReader interface {
	ReadReceipt() (*rpctypes.RawTxReceipt, error)
}

func OpenReceiptReader added in v0.1.17

func OpenReceiptReader(file string, mode string) (ReceiptReader, error)

OpenReceiptReader returns a receipt reader object which can be used to read the file. It will return a mode specific receipt reader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL