The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/p2p/stream/protocols/sync/message/compose.go

365 lines
10 KiB

package message
import (
"github.com/ethereum/go-ethereum/common"
)
// MakeGetBlockNumberRequest makes the GetBlockNumber Request
func MakeGetBlockNumberRequest() *Request {
return &Request{
Request: &Request_GetBlockNumberRequest{
GetBlockNumberRequest: &GetBlockNumberRequest{},
},
}
}
// MakeGetBlockHashesRequest makes GetBlockHashes Request
func MakeGetBlockHashesRequest(bns []uint64) *Request {
return &Request{
Request: &Request_GetBlockHashesRequest{
GetBlockHashesRequest: &GetBlockHashesRequest{
Nums: bns,
},
},
}
}
// MakeGetBlocksByNumRequest makes the GetBlockByNumber request
func MakeGetBlocksByNumRequest(bns []uint64) *Request {
return &Request{
Request: &Request_GetBlocksByNumRequest{
GetBlocksByNumRequest: &GetBlocksByNumRequest{
Nums: bns,
},
},
}
}
Release Candidate hotfix: dev -> main (#4333) * Rebase dev branch to current main branch (#4318) * add openssl compatibility on m2 chips using darwin (#4302) Adds support for OpenSSL on MacOS Ventura using m2 chips. * [dumpdb] ensure each cross link is dumped (#4311) * bump libp2p to version 0.24.0 and update its dependencies and relevant tests (#4315) * Removed legacy syncing peer provider. (#4260) * Removed legacy syncing peer provider. * Fix localnet. * Fix migrate version. * Rebased on main. * Fix formatting. * Remove blockchain dependency from engine. (#4310) * Consensus doesn't require anymore `Node` as a circular dependency. * Rebased upon main. * Removed engine beacon chain dependency. * Fixed nil error. * Fixed error. * bump libp2p to version 0.24.0 and update its dependencies and relevant tests * fix format, remove wrongly added configs * add back wrongly deleted comment * fix travis go checker Co-authored-by: Konstantin <355847+Frozen@users.noreply.github.com> Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”> * bump libp2p to version 0.24.0 and update its dependencies and relevant tests (#4315) * Removed legacy syncing peer provider. (#4260) * Removed legacy syncing peer provider. * Fix localnet. * Fix migrate version. * Rebased on main. * Fix formatting. * Remove blockchain dependency from engine. (#4310) * Consensus doesn't require anymore `Node` as a circular dependency. * Rebased upon main. * Removed engine beacon chain dependency. * Fixed nil error. * Fixed error. * bump libp2p to version 0.24.0 and update its dependencies and relevant tests * fix format, remove wrongly added configs * add back wrongly deleted comment * fix travis go checker Co-authored-by: Konstantin <355847+Frozen@users.noreply.github.com> Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”> * Fix for consensus stuck. (#4307) * Added check for block validity. * Starts new view change if block invalid. * Revert "Starts new view change if block invalid." This reverts commit e889fa5da2e0780f087ab7dae5106b96287706db. * staged dns sync v1.0 (#4316) * staged dns sync v1.0 * enabled stream downloader for localnet * fix code review issues * remove extra lock Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”> * add description for closing client and change randomize process to ma… (#4276) * add description for closing client and change randomize process to make sure only online nodes are added to sync config * fix sync test * fix legacy limitNumPeers test * add WaitForEachPeerToConnect to node configs to make parallel peer connection optional Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”> * Small fixes and code cleanup for network stack. (#4320) * staged dns sync v1.0 * enabled stream downloader for localnet * fix code review issues * remove extra lock * staged dns sync v1.0 * Fixed, code clean up and other. * Fixed, code clean up and other. * Fixed, code clean up and other. * Fix config. Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”> * Fix not disable cache in archival mode (#4322) * Feature registry (#4324) * Registry for services. * Test. * Reverted comment. * Fix. * Slash fix (#4284) * Implementation of new slashing rate calculation * Write tests for then new slashing rate calculation * Add engine.applySlashing tests * fix #4059 Co-authored-by: Alex Brezas <abresas@gmail.com> Co-authored-by: Dimitris Lamprinos <pkakelas@gmail.com> * Bump github.com/aws/aws-sdk-go from 1.30.1 to 1.33.0 (#4325) (#4328) Bumps [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) from 1.30.1 to 1.33.0. - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Changelog](https://github.com/aws/aws-sdk-go/blob/v1.33.0/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-go/compare/v1.30.1...v1.33.0) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump github.com/btcsuite/btcd from 0.21.0-beta to 0.23.2 (#4327) (#4329) Bumps [github.com/btcsuite/btcd](https://github.com/btcsuite/btcd) from 0.21.0-beta to 0.23.2. - [Release notes](https://github.com/btcsuite/btcd/releases) - [Changelog](https://github.com/btcsuite/btcd/blob/master/CHANGES) - [Commits](https://github.com/btcsuite/btcd/compare/v0.21.0-beta...v0.23.2) --- updated-dependencies: - dependency-name: github.com/btcsuite/btcd dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix epoch chain initialization issue (#4331) * Fix getting epoch number. (#4279) * feat: update dockerfile with some enhacement (#4250) * feat: update dockerfile with some enhancement * [docker] fix: update golang version Co-authored-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com> * [build] github action update (#4336) * [ops] update github action files * [ops] add debug message in github action * [ops] fix GPG action variable * [ops] fix macos-12 build * [ops] fix macos-12 build * [ops] fix macos-12 build * [ops] fix macos-12 build * [ops] fix macos-12 build * [ops] fix macos-12 build * [cmd] update year version (#4334) * chore(build): upgrade golang to 1.19 (#4335) * chore(build): upgrade golang to 1.19 * chore(build): run `go mod tidy` * chore(build): run `goimports -w -e ${file}` * chore(build): revert github ci changes * chore(build): pin golang version to 1.19.5 * chore(build): fix protoc version on gen files * chore(build): fix protoc-gen-go to v1.26.0 (#4337) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Max <82761650+MaxMustermann2@users.noreply.github.com> Co-authored-by: Gheis <36589218+GheisMohammadi@users.noreply.github.com> Co-authored-by: Konstantin <355847+Frozen@users.noreply.github.com> Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”> Co-authored-by: Danny Willis <102543677+dannyposi@users.noreply.github.com> Co-authored-by: PeekPI <894646171@QQ.COM> Co-authored-by: Alex Brezas <abresas@gmail.com> Co-authored-by: Dimitris Lamprinos <pkakelas@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Gheis Mohammadi <Gheis.Mohammadi@gmail.com> Co-authored-by: Jason Yi <90701258+jasonyic@users.noreply.github.com> Co-authored-by: Soph <35721420+sophoah@users.noreply.github.com>
2 years ago
// MakeGetBlockByHashesRequest makes the GetBlocksByHashes request
func MakeGetBlocksByHashesRequest(hashes []common.Hash) *Request {
return &Request{
Request: &Request_GetBlocksByHashesRequest{
GetBlocksByHashesRequest: &GetBlocksByHashesRequest{
BlockHashes: hashesToBytes(hashes),
},
},
}
}
// MakeGetNodeDataRequest makes the GetNodeData request
func MakeGetNodeDataRequest(hashes []common.Hash) *Request {
return &Request{
Request: &Request_GetNodeDataRequest{
GetNodeDataRequest: &GetNodeDataRequest{
NodeHashes: hashesToBytes(hashes),
},
},
}
}
// MakeGetReceiptsRequest makes the GetReceipts request
func MakeGetReceiptsRequest(hashes []common.Hash) *Request {
return &Request{
Request: &Request_GetReceiptsRequest{
GetReceiptsRequest: &GetReceiptsRequest{
BlockHashes: hashesToBytes(hashes),
},
},
}
}
// MakeGetAccountRangeRequest makes the GetAccountRange request
func MakeGetAccountRangeRequest(root common.Hash, origin common.Hash, limit common.Hash, bytes uint64) *Request {
return &Request{
Request: &Request_GetAccountRangeRequest{
GetAccountRangeRequest: &GetAccountRangeRequest{
Root: root[:],
Origin: origin[:],
Limit: limit[:],
Bytes: bytes,
},
},
}
}
// MakeGetStorageRangesRequest makes the GetStorageRanges request
func MakeGetStorageRangesRequest(root common.Hash, accounts []common.Hash, origin common.Hash, limit common.Hash, bytes uint64) *Request {
return &Request{
Request: &Request_GetStorageRangesRequest{
GetStorageRangesRequest: &GetStorageRangesRequest{
Root: root[:],
Accounts: hashesToBytes(accounts),
Origin: origin[:],
Limit: limit[:],
Bytes: bytes,
},
},
}
}
// MakeGetByteCodesRequest makes the GetByteCodes request
func MakeGetByteCodesRequest(hashes []common.Hash, bytes uint64) *Request {
return &Request{
Request: &Request_GetByteCodesRequest{
GetByteCodesRequest: &GetByteCodesRequest{
Hashes: hashesToBytes(hashes),
Bytes: bytes,
},
},
}
}
// MakeGetTrieNodesRequest makes the GetTrieNodes request
func MakeGetTrieNodesRequest(root common.Hash, paths []*TrieNodePathSet, bytes uint64) *Request {
return &Request{
Request: &Request_GetTrieNodesRequest{
GetTrieNodesRequest: &GetTrieNodesRequest{
Root: root[:],
Paths: paths,
Bytes: bytes,
},
},
}
}
// MakeErrorResponse makes the error response
func MakeErrorResponseMessage(rid uint64, err error) *Message {
resp := MakeErrorResponse(rid, err)
return makeMessageFromResponse(resp)
}
// MakeErrorResponse makes the error response as a response
func MakeErrorResponse(rid uint64, err error) *Response {
return &Response{
ReqId: rid,
Response: &Response_ErrorResponse{
&ErrorResponse{
Error: err.Error(),
},
},
}
}
// MakeGetBlockNumberResponseMessage makes the GetBlockNumber response message
func MakeGetBlockNumberResponseMessage(rid uint64, bn uint64) *Message {
resp := MakeGetBlockNumberResponse(rid, bn)
return makeMessageFromResponse(resp)
}
// MakeGetBlockNumberResponse makes the GetBlockNumber response
func MakeGetBlockNumberResponse(rid uint64, bn uint64) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetBlockNumberResponse{
GetBlockNumberResponse: &GetBlockNumberResponse{
Number: bn,
},
},
}
}
// MakeGetBlockHashesResponseMessage makes the GetBlockHashes message
func MakeGetBlockHashesResponseMessage(rid uint64, hs []common.Hash) *Message {
resp := MakeGetBlockHashesResponse(rid, hs)
return makeMessageFromResponse(resp)
}
// MakeGetBlockHashesResponse makes the GetBlockHashes response
func MakeGetBlockHashesResponse(rid uint64, hs []common.Hash) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetBlockHashesResponse{
GetBlockHashesResponse: &GetBlockHashesResponse{
Hashes: hashesToBytes(hs),
},
},
}
}
// MakeGetBlocksByNumResponseMessage makes the GetBlocksByNumResponse of Message type
func MakeGetBlocksByNumResponseMessage(rid uint64, blocksBytes, sigs [][]byte) *Message {
resp := MakeGetBlocksByNumResponse(rid, blocksBytes, sigs)
return makeMessageFromResponse(resp)
}
// MakeGetBlocksByNumResponseMessage make the GetBlocksByNumResponse of Response type
func MakeGetBlocksByNumResponse(rid uint64, blocksBytes, sigs [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetBlocksByNumResponse{
GetBlocksByNumResponse: &GetBlocksByNumResponse{
BlocksBytes: blocksBytes,
CommitSig: sigs,
},
},
}
}
// MakeGetBlocksByHashesResponseMessage makes the GetBlocksByHashesResponse of Message type
func MakeGetBlocksByHashesResponseMessage(rid uint64, blocksBytes, sigs [][]byte) *Message {
resp := MakeGetBlocksByHashesResponse(rid, blocksBytes, sigs)
return makeMessageFromResponse(resp)
}
// MakeGetBlocksByHashesResponse make the GetBlocksByHashesResponse of Response type
func MakeGetBlocksByHashesResponse(rid uint64, blocksBytes [][]byte, sigs [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetBlocksByHashesResponse{
GetBlocksByHashesResponse: &GetBlocksByHashesResponse{
BlocksBytes: blocksBytes,
CommitSig: sigs,
},
},
}
}
// MakeGetNodeDataResponseMessage makes the GetNodeDataResponse of Message type
func MakeGetNodeDataResponseMessage(rid uint64, nodeData [][]byte) *Message {
resp := MakeGetNodeDataResponse(rid, nodeData)
return makeMessageFromResponse(resp)
}
// MakeGetNodeDataResponse make the GetNodeDataResponse of Response type
func MakeGetNodeDataResponse(rid uint64, nodeData [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetNodeDataResponse{
GetNodeDataResponse: &GetNodeDataResponse{
DataBytes: nodeData,
},
},
}
}
// MakeGetReceiptsResponseMessage makes the GetReceiptsResponse of Message type
func MakeGetReceiptsResponseMessage(rid uint64, receipts map[uint64]*Receipts) *Message {
resp := MakeGetReceiptsResponse(rid, receipts)
return makeMessageFromResponse(resp)
}
// MakeGetReceiptsResponse make the GetReceiptsResponse of Response type
func MakeGetReceiptsResponse(rid uint64, receipts map[uint64]*Receipts) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetReceiptsResponse{
GetReceiptsResponse: &GetReceiptsResponse{
Receipts: receipts,
},
},
}
}
// MakeGetAccountRangeResponseMessage makes the GetAccountRangeResponse of Message type
func MakeGetAccountRangeResponseMessage(rid uint64, accounts []*AccountData, proof [][]byte) *Message {
resp := MakeGetAccountRangeResponse(rid, accounts, proof)
return makeMessageFromResponse(resp)
}
// MakeGetAccountRangeResponse make the GetAccountRangeResponse of Response type
func MakeGetAccountRangeResponse(rid uint64, accounts []*AccountData, proof [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetAccountRangeResponse{
GetAccountRangeResponse: &GetAccountRangeResponse{
Accounts: accounts,
Proof: proof,
},
},
}
}
// MakeGetStorageRangesResponseMessage makes the GetStorageRangesResponse of Message type
func MakeGetStorageRangesResponseMessage(rid uint64, slots []*StoragesData, proof [][]byte) *Message {
resp := MakeGetStorageRangesResponse(rid, slots, proof)
return makeMessageFromResponse(resp)
}
// MakeGetStorageRangesResponse make the GetStorageRangesResponse of Response type
func MakeGetStorageRangesResponse(rid uint64, slots []*StoragesData, proof [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetStorageRangesResponse{
GetStorageRangesResponse: &GetStorageRangesResponse{
Slots: slots,
Proof: proof,
},
},
}
}
// MakeGetByteCodesResponseMessage makes the GetByteCodesResponse of Message type
func MakeGetByteCodesResponseMessage(rid uint64, codes [][]byte) *Message {
resp := MakeGetByteCodesResponse(rid, codes)
return makeMessageFromResponse(resp)
}
// MakeGetByteCodesResponse make the GetByteCodesResponse of Response type
func MakeGetByteCodesResponse(rid uint64, codes [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetByteCodesResponse{
GetByteCodesResponse: &GetByteCodesResponse{
Codes: codes,
},
},
}
}
// MakeGetTrieNodesResponseMessage makes the GetTrieNodesResponse of Message type
func MakeGetTrieNodesResponseMessage(rid uint64, nodes [][]byte) *Message {
resp := MakeGetTrieNodesResponse(rid, nodes)
return makeMessageFromResponse(resp)
}
// MakeGetTrieNodesResponse make the GetTrieNodesResponse of Response type
func MakeGetTrieNodesResponse(rid uint64, nodes [][]byte) *Response {
return &Response{
ReqId: rid,
Response: &Response_GetTrieNodesResponse{
GetTrieNodesResponse: &GetTrieNodesResponse{
Nodes: nodes,
},
},
}
}
// MakeMessageFromRequest makes a message from the request
func MakeMessageFromRequest(req *Request) *Message {
return &Message{
ReqOrResp: &Message_Req{
Req: req,
},
}
}
func makeMessageFromResponse(resp *Response) *Message {
return &Message{
ReqOrResp: &Message_Resp{
Resp: resp,
},
}
}
func hashesToBytes(hashes []common.Hash) [][]byte {
res := make([][]byte, 0, len(hashes))
for _, h := range hashes {
b := make([]byte, common.HashLength)
copy(b, h[:])
res = append(res, b)
}
return res
}
func bytesToHashes(bs [][]byte) []common.Hash {
res := make([]common.Hash, len(bs))
for _, b := range bs {
var h common.Hash
copy(h[:], b)
res = append(res, h)
}
return res
}