dominant-strategies / go-quai Goto Github PK
View Code? Open in Web Editor NEWOfficial Go Implementation of the Quai Network
License: GNU General Public License v3.0
Official Go Implementation of the Quai Network
License: GNU General Public License v3.0
When an external block is gathered by a recieving context at a coincident block. Any transaction should be checked to make sure that:
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
After compling the core package, the Homestead config test is failing due to not finding a compatability error.
https://github.com/spruce-solutions/go-quai/blob/894f0bb61b03af1932741a932ea51216246ee0d3/core/genesis_test.go#L42-L42
Required Steps:
Required Tests:
Things to keep in mind:
The connector package will be responsible for:
consensus/ethash/consensus.go
.The README should be updated to reflect:
The merklization of the transactions array will need to be coordinated in a fashion that allows for the easy lookup and retrieval of ETxs.
Need to triple check difficulty when adding ETxs from a trace branch.
Unsure why ourTD is using the header with number beyond what was imported. Unable to find where it could be incrementing the number. This gives the wrong hash for the difficulty computation.
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
}
All references to go-ethereum will need replacing with go-quai.
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
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
}
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:
*lru.Cache
for fast look up during validation.Quai will utilize the Chain ID portion of the config to separate each context and to differentiate between mainnet and testnet. Changes will need to be made wherever ChainFlag
or ChainID
is referenced.
Example of existing code:
https://github.com/spruce-solutions/go-quai/blob/0e2b90ec3f183c3112bc84e5d4db231a7454d52f/cmd/utils/flags.go#L1296-L1316
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:
Use the new TotalBitLen to calculate the number of bits used in each header field.
A basic fastcache has been implemented, additional features yet to be implemented:
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
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.