GithubHelp home page GithubHelp logo

dominant-strategies / go-quai Goto Github PK

View Code? Open in Web Editor NEW
2.4K 2.4K 456.0 76.68 MB

Official Go Implementation of the Quai Network

License: GNU General Public License v3.0

Shell 0.14% Dockerfile 0.02% Makefile 0.16% Go 98.56% Assembly 0.61% NSIS 0.45% Ruby 0.02% Smarty 0.04%

go-quai's People

Contributors

alanorwick avatar didaunesp avatar djadih avatar gameofpointers avatar hubchub avatar jdowning100 avatar kiltsonfire avatar maxbibeau avatar robertlincecum avatar robschleusner avatar skeptrunedev avatar wizeguyy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-quai's Issues

Integration Tests for TraceBranches

Required Steps:

  1. Generate proper addresses
  2. Generate spoof chains with transactions included that end up in the external block cache
  3. Make sure chains run long enough to flush state
  4. Need to make sure we audit all state transitions and can confirm across chains

Required Tests:

  • Region to Prime
  • Prime to Region
  • Zone to Prime
  • Prime to Zone
  • Region to Region (through Prime)
  • Zone to Zone (through Region)
  • Zone to Zone through Prime)

Things to keep in mind:

  • Ordering of transactions
  • Queueing of transactions
  • Validity of transactions (inoperable vs. operable)
  • Removing of blocks from cache
  • All blocks are traced only once at the right time

Implement Connector Package

The connector package will be responsible for:

  • Deterministically finding all headers linked between coincident blocks.
  • Lookup of each header in the ExternalBlock cache.
  • Manage requesting a missing block header or body from the manager via RPC.
  • Retrieving ETxs from an ExternalBlock.
  • Passing all ETxs to the finalization of state in consensus/ethash/consensus.go.

Implement ExternalBlock Type and Cache

ExternalBlocks are blocks that are sent from the manager with external transactions terminating in the receiving nodes context. We break down a standard block into an ExternalBlock in order to save space on disk for validating and time downloading from manager.

An ExternalBlock struct will look roughly like this:

// ExternalBlock represents an external block with transactions destined for a specific context.
type ExternalBlock struct {
	header       *Header
	externalTxs  Transactions
	originLocation byte
	
	// caches
	hash atomic.Value
	size atomic.Value

	// Td is used by package core to store the total difficulty
	// of the chain up to and including the block.
	td *big.Int

	// These fields are used by package eth to track
	// inter-peer block relay.
	ReceivedAt   time.Time
	ReceivedFrom interface{}
}

Implementation requirements:

  • External Block cache of type *lru.Cache for fast look up during validation.
  • Method of listening for blocks from manager to update the cache.

Double check header.Time < parent.Time in consensus.go

The boolean check has been changed from <= to < in the below code in consensus.go. It would be good to double check whether this has any large downstream impacts. The change was made due to Zone blocks being triggered on it when receiving Region block txs.

if header.Time < parent.Time {
		return errOlderBlockTime
}

Block Header Modification

Quai block headers must be updated to the following:

type Header struct {
    ParentHash  []common.Hash    `json:"parentHash"       gencodec:"required"`
    UncleHash   []common.Hash    `json:"sha3Uncles"       gencodec:"required"`
    Coinbase    []common.Address `json:"miner"            gencodec:"required"`
    Root        []common.Hash    `json:"stateRoot"        gencodec:"required"`
    TxHash      []common.Hash    `json:"transactionsRoot" gencodec:"required"`
    ReceiptHash []common.Hash    `json:"receiptsRoot"     gencodec:"required"`
    Bloom       []Bloom          `json:"logsBloom"        gencodec:"required"`
    Difficulty  []*big.Int       `json:"difficulty"       gencodec:"required"`
    Number      []*big.Int       `json:"number"           gencodec:"required"`
    GasLimit    uint64         `json:"gasLimit"         gencodec:"required"`
    GasUsed     uint64         `json:"gasUsed"          gencodec:"required"`
    Time        uint64         `json:"timestamp"        gencodec:"required"`
    Extra       []byte         `json:"extraData"        gencodec:"required"`
    MixDigest   common.Hash    `json:"mixHash"`
    Nonce       BlockNonce     `json:"nonce"`

    // BaseFee was added by EIP-1559 and is ignored in legacy headers.
    BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`

    // New
    // Map the current Region / Zone 
    MapContext  []byte

    Location    []byte
}

In the following file:
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/types/block.go#L73-L93

Tests that must be updated:
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/types/block_test.go#L36
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/types/block_test.go#L72
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/types/block_test.go#L139
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/types/block_test.go#L208
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/types/block_test.go#L231

Implement External Transaction Type

External transactions, which will now be referred to as a ETx(s), are transactions that affect state across Quai contexts. An example of an ETx is a tx that sends QUAI from Region 0 Zone 0 to Region 1 Zone 3. This ETx will need to be recorded via the UTXO connector in Region 0, Prime, and Region 1 before ultimately modifying state in Zone 3.

ETxs will roughly look like:

// ExternalTx is the data of EIP-2930 access list transactions.
type ExternalTx struct {
    ChainID         *big.Int        // destination chain ID
    Nonce           uint64          // nonce of sender account
    GasPrice        *big.Int        // wei per gas
    Gas             uint64          // gas limit
    FromAddress     *common.Address `rlp:"nil"` // nil means contract creation
    FromLocation    byte            // origin location in bytes for tx 
    ToAddress       *common.Address `rlp:"nil"` // nil means contract creation
    ToLocation      byte            // destination location in bytes for tx
    Value           *big.Int        // wei amount
    V, R, S         *big.Int        // signature values
}

Tests will need to be created in a similar fashion to the other transaction tests

External Block Cache Full Scope

A basic fastcache has been implemented, additional features yet to be implemented:

  1. Blocks will need to be removed from the external block cache after a certain interval
  2. Retrieve missing blocks from manager or peers
  3. Struct containing cache that has proper methods

Genesis Struct Creation Implementation

The Genesis struct must be updated to accommodate for Quai block headers.

type Genesis struct {
	Config     *params.ChainConfig `json:"config"`
	Nonce      uint64              `json:"nonce"`
	Timestamp  uint64              `json:"timestamp"`
	ExtraData  [][]byte            `json:"extraData"`
	GasLimit   []uint64            `json:"gasLimit"   gencodec:"required"`
	Difficulty []*big.Int          `json:"difficulty" gencodec:"required"`
	Mixhash    []common.Hash       `json:"mixHash"`
	Coinbase   []common.Address    `json:"coinbase"`
	Alloc      []GenesisAlloc      `json:"alloc"      gencodec:"required"`
	SealRlp    []byte              `json:"sealRlp"`

	// These fields are used for consensus tests. Please don't use them
	// in actual genesis blocks.
	Number     []uint64      `json:"number"`
	GasUsed    []uint64      `json:"gasUsed"`
	ParentHash []common.Hash `json:"parentHash"`
	BaseFee    []*big.Int    `json:"baseFee"`
}

Genesis struct is found here:
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/genesis.go#L57-L75

Other modifications:

  1. Marshal and unmarshal of Genesis JSON
    https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/core/gen_genesis.go#L19

Change Byte ID for address space to range instead of fixed value

params/config.go

func init() {
	bytePrefixList[9000] = byte(0)
	bytePrefixList[9100] = byte(10)
	bytePrefixList[9101] = byte(26)
	bytePrefixList[9102] = byte(42)
	bytePrefixList[9103] = byte(58)
	bytePrefixList[9200] = byte(11)
	bytePrefixList[9201] = byte(27)
	bytePrefixList[9202] = byte(43)
	bytePrefixList[9203] = byte(59)
	bytePrefixList[9300] = byte(12)
	bytePrefixList[9301] = byte(28)
	bytePrefixList[9302] = byte(44)
	bytePrefixList[9303] = byte(60)
}

// ChainIDByte returns the byte lookup based off a configs chainID
func (c *ChainConfig) ChainIDByte() byte {
	lookup := bytePrefixList[c.ChainID.Int64()]
	return lookup
}

// ChainIDByte returns the byte lookup based off a configs chainID
func LookupChainByte(index *big.Int) byte {
	lookup := bytePrefixList[index.Int64()]
	return lookup
}

// ValidChainID takes in a chain ID and checks against the valid list
func ValidChainID(id *big.Int) bool {
	for _, valid := range validChains {
		if id.Cmp(valid) == 0 {
			return true
		}
	}
	return false
}

RPC Method Updates for Manager

Note to self on RPCMarshalHeader:

// RPCMarshalHeader converts the given header to the RPC output .
func RPCMarshalHeader(head *types.Header) map[string]interface{} {
	result := map[string]interface{}{
		"number":           head.Number,
		"hash":             head.Hash(),
		"parentHash":       head.ParentHash,
		"nonce":            head.Nonce,
		"mixHash":          head.MixDigest,
		"sha3Uncles":       head.UncleHash,
		"logsBloom":        head.Bloom,
		"stateRoot":        head.Root,
		"miner":            head.Coinbase,
		"difficulty":       head.Difficulty,
		"extraData":        head.Extra,
		"size":             hexutil.Uint64(head.Size()),
		"gasLimit":         head.GasLimit,
		"gasUsed":          head.GasUsed,
		"timestamp":        head.Time,
		"transactionsRoot": head.TxHash,
		"receiptsRoot":     head.ReceiptHash,
	}

	if head.BaseFee != nil {
		result["baseFeePerGas"] = head.BaseFee
	}

	return result
}

Quai README Overview

The README should be updated to reflect:

  • An overview of Quai.
  • How merged mining works.
  • What is needed to run Quai.
  • Reasoning for why we went with the Erigon implementation of Geth.
  • Requirements for working with quai-manager.
  • RPC descriptions.
  • Mining instructions.

Check valid state context of recieving external txs

When an external block is gathered by a recieving context at a coincident block. Any transaction should be checked to make sure that:

  1. the tx status is valid
  2. the receiving context matches the output of the transaction
  3. the sending context matches the input of the transaction

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.