Skip to content

Commit

Permalink
Merged main changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shreekarashastry committed Jun 30, 2022
2 parents 8339997 + 4700b0a commit a0c397a
Show file tree
Hide file tree
Showing 40 changed files with 877 additions and 104 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Go

on:
pull_request:
types: [closed]
branches: [ "main" ]
jobs:

build:
if: github.event.pull_request.merged == true

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: main

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17

- name: Install dependencies
run: sudo apt-get install make build-essential

- name: Install yq
run: sudo snap install yq

- name: create network.env
run: cat ./network.env.dist | sed "s/WS_API=eth,net,web3,quai/WS_API=eth,net,web3,quai,txpool/g" | sed "s/HTTP_API=eth,net,web3/HTTP_API=eth,net,web3,quai,txpool/g" | sed "s/CORS=false/CORS=true/g" > ./network.env

#- name: build
# run: go run build/ci.go install ./cmd/quai

#- name: Build
# run: make go-quai

#- name: Test
# run: go test -v

- name: Build Docker
run: docker build . -t quainetwork/go-quai:$(cat VERSION) -t quainetwork/go-quai:latest

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: quaibuild
password: ${{ secrets.DOCKER }}

- name: show
run: docker push quainetwork/go-quai:$(cat VERSION)

- name: git tag
run: git tag $(cat VERSION) && git push origin $(cat VERSION)


# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}

- uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e
with:
cluster_name: quai-prod
location: us-central1-c
credentials: ${{ secrets.GKE_SA_KEY }}

- name: Deploy
uses: WyriHaximus/github-action-helm3@v2
with:
exec: helm upgrade go-quai ./helm --install --wait --atomic --namespace=quai-prod --values=./helm/env/quai-prod.values.yaml

- name: Update version
run: awk -F. '{print $1"."$2"."$3"."$4+1}' VERSION > tmp && mv tmp VERSION

- name: Update Chart.yaml version
run: yq eval ".appVersion=\"$(cat VERSION)\"" ./helm/Chart.yaml > ./helm/Chart.yaml
- name: Update values.yaml version
run: yq eval ".goQuai.image.version=\"$(cat VERSION)\"" ./helm/values.yaml > ./helm/values.yaml

- name: remove kubeconfig
run: rm $KUBECONFIG

- uses: stefanzweifel/git-auto-commit-action@v4

deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.0-pre.1
49 changes: 40 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var (

errInsertionInterrupted = errors.New("insertion is interrupted")
errChainStopped = errors.New("blockchain is stopped")
errExtBlockNotFound = errors.New("error finding external block by context and hash")
)

const (
Expand Down Expand Up @@ -1619,9 +1620,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.

// WriteBlockWithState writes the block and all associated state to the database.
func (bc *BlockChain) WriteBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, linkExtBlocks []*types.ExternalBlock, emitHeadEvent bool) (status WriteStatus, err error) {
if !bc.chainmu.TryLock() {
return NonStatTy, errChainStopped
}
bc.chainmu.Lock()
defer bc.chainmu.Unlock()

return bc.writeBlockAndSetHead(block, receipts, logs, state, linkExtBlocks, emitHeadEvent)
Expand Down Expand Up @@ -1723,8 +1722,8 @@ func (bc *BlockChain) AddExternalBlock(block *types.ExternalBlock) error {

// ReOrgRollBack compares the difficulty of the newchain and oldchain. Rolls back
// the current header to the position where the reorg took place in a higher context
func (bc *BlockChain) ReOrgRollBack(header *types.Header) error {
log.Info("Rolling back header beyond", "hash", header.Hash())
func (bc *BlockChain) ReOrgRollBack(header *types.Header, validHeaders []*types.Header, invalidHeaders []*types.Header) error {
log.Info("Rolling back header beyond", "hash", header.Hash(), "from", bc.CurrentBlock().Header().Hash())
bc.reorgmu.Lock()
defer bc.reorgmu.Unlock()
var (
Expand Down Expand Up @@ -2831,7 +2830,7 @@ func (bc *BlockChain) GetExternalBlock(hash common.Hash, location []byte, contex
if block == nil {
block = bc.requestExternalBlock(hash, location, context)
if block == nil {
return &types.ExternalBlock{}, errors.New("error finding external block by context and hash")
return &types.ExternalBlock{}, errExtBlockNotFound
}
}
return block, nil
Expand Down Expand Up @@ -3089,7 +3088,20 @@ func (bc *BlockChain) PCRC(header *types.Header) (common.Hash, error) {
return common.Hash{}, err
}

// PCRC has failed. Rollback through the prior untwisted region.
if RTZ.Hash() != RTR.Hash() {
log.Info("Error in PCRC", "RTZ:", RTZ.Hash(), "RTR:", RTR.Hash())
// If we are running in Prime or Region and have failed PCRC
// 1. Check to see if the Zone terminus is on our chain.
// 2. If Zone terminus is in our chain, do nothing.
// 3. If Zone terminus is not in our chain, uncle the RTZ in the subordinate context.
if types.QuaiNetworkContext < params.ZONE {
rtz := bc.hc.GetBlockNumber(RTZ.Hash())
// rtz is not in our Region chain, remove it from subordinate chains.
if rtz == nil {
bc.chainUncleFeed.Send(RTZ)
}
}
return common.Hash{}, errors.New("there exists a region twist")
}
}
Expand All @@ -3107,18 +3119,37 @@ func (bc *BlockChain) PCRC(header *types.Header) (common.Hash, error) {

// Only check for prime twist if block is of prime order
if headerOrder == params.PRIME {

PTR, err := bc.Engine().PreviousCoincidentOnPath(bc, header, slice, params.PRIME, params.REGION)
if err != nil {
return common.Hash{}, err
}

PTP, err := bc.Engine().PreviousCoincidentOnPath(bc, header, slice, params.PRIME, params.PRIME)
if err != nil {
return common.Hash{}, err
}

if PTZ.Hash() != PTR.Hash() || PTR.Hash() != PTP.Hash() || PTP.Hash() != PTZ.Hash() {
// PCRC has failed. Rollback through the prior untwisted prime.
if PTR.Hash() != PTP.Hash() {
log.Info("Error in PCRC", "PTR:", PTR.Hash(), "RTR:", PTP.Hash())
if types.QuaiNetworkContext < params.REGION {
ptr := bc.hc.GetBlockNumber(PTR.Hash())
// ptr is not in our Prime chain, remove it from subordinate chains.
if ptr == nil {
bc.chainUncleFeed.Send(PTR)
}
}
return common.Hash{}, errors.New("there exists a prime twist")
}

if PTZ.Hash() != PTR.Hash() {
log.Info("Error in PCRC", "PTZ:", PTZ.Hash(), "PTR:", PTR.Hash())
if types.QuaiNetworkContext < params.REGION {
ptz := bc.hc.GetBlockNumber(PTZ.Hash())
// ptz is not in our Prime chain, remove it from subordinate chains.
if ptz == nil {
bc.chainUncleFeed.Send(PTZ)
}
}
return common.Hash{}, errors.New("there exists a prime twist")
}
}
Expand Down
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ func (b *EthAPIBackend) AddExternalBlock(block *types.ExternalBlock) error {
return b.eth.blockchain.AddExternalBlock(block)
}

func (b *EthAPIBackend) ReOrgRollBack(header *types.Header) error {
return b.eth.blockchain.ReOrgRollBack(header)
func (b *EthAPIBackend) ReOrgRollBack(header *types.Header, validDoms []*types.Header, invalidDoms []*types.Header) error {
return b.eth.blockchain.ReOrgRollBack(header, validDoms, invalidDoms)
}

func (b *EthAPIBackend) GetExternalBlockTraceSet(header *types.Header, context int) (*types.ExternalBlock, error) {
Expand Down
15 changes: 9 additions & 6 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ type BlockChain interface {

// Adds ExternalBlock to external block cache
AddExternalBlock(block *types.ExternalBlock) error

// HLCR does hierarchical comparison of two difficulty tuples and returns true if second tuple is greater than the first
HLCR(localDifficulties []*big.Int, externDifficulties []*big.Int) bool
}

// New creates a new downloader to fetch hashes and blocks from remote peers.
Expand Down Expand Up @@ -331,7 +334,7 @@ func (d *Downloader) UnregisterPeer(id string) error {

// Synchronise tries to sync up our local block chain with a remote peer, both
// adding various sanity checks as well as wrapping it with various log entries.
func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode SyncMode) error {
func (d *Downloader) Synchronise(id string, head common.Hash, td []*big.Int, mode SyncMode) error {
err := d.synchronise(id, head, td, mode)

switch err {
Expand All @@ -358,7 +361,7 @@ func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode
// synchronise will select the peer and use it for synchronising. If an empty string is given
// it will use the best peer possible and synchronize if its TD is higher than our own. If any of the
// checks fail an error will be returned. This method is synchronous
func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode SyncMode) error {
func (d *Downloader) synchronise(id string, hash common.Hash, td []*big.Int, mode SyncMode) error {
// Mock out the synchronisation if testing
if d.synchroniseMock != nil {
return d.synchroniseMock(id, hash)
Expand Down Expand Up @@ -446,7 +449,7 @@ func (d *Downloader) getMode() SyncMode {

// syncWithPeer starts a block synchronization based on the hash chain from the
// specified peer and head hash.
func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.Int) (err error) {
func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td []*big.Int) (err error) {
d.mux.Post(StartEvent{})
defer func() {
// reset on error
Expand Down Expand Up @@ -1552,7 +1555,7 @@ func (d *Downloader) fetchParts(deliveryCh chan dataPack, deliver func(dataPack)
// processHeaders takes batches of retrieved headers from an input channel and
// keeps processing and scheduling them into the header chain and downloader's
// queue until the stream ends or a failure occurs.
func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
func (d *Downloader) processHeaders(origin uint64, td []*big.Int) error {
// Keep a count of uncertain headers to roll back
var (
rollback uint64 // Zero means no rollback (fine as you can't unroll the genesis)
Expand Down Expand Up @@ -1614,7 +1617,7 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
// R: Nothing to give
if mode != LightSync {
head := d.blockchain.CurrentBlock()
if !gotHeaders && td.Cmp(d.blockchain.GetTd(head.Hash(), head.NumberU64())[types.QuaiNetworkContext]) > 0 {
if !gotHeaders && d.blockchain.HLCR(d.blockchain.GetTd(head.Hash(), head.NumberU64()), td) {
return errStallingPeer
}
}
Expand All @@ -1627,7 +1630,7 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
// peer gave us something useful, we're already happy/progressed (above check).
if mode == FastSync || mode == LightSync {
head := d.lightchain.CurrentHeader()
if td.Cmp(d.lightchain.GetTd(head.Hash(), head.Number[types.QuaiNetworkContext].Uint64())[types.QuaiNetworkContext]) > 0 {
if d.blockchain.HLCR(d.lightchain.GetTd(head.Hash(), head.Number[types.QuaiNetworkContext].Uint64()), td) {
return errStallingPeer
}
}
Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type peerConnection struct {

// LightPeer encapsulates the methods required to synchronise with a remote light peer.
type LightPeer interface {
Head() (common.Hash, *big.Int)
Head() (common.Hash, []*big.Int)
RequestHeadersByHash(common.Hash, int, int, bool) error
RequestHeadersByNumber(uint64, int, int, bool) error
}
Expand All @@ -91,7 +91,7 @@ type lightPeerWrapper struct {
peer LightPeer
}

func (w *lightPeerWrapper) Head() (common.Hash, *big.Int) { return w.peer.Head() }
func (w *lightPeerWrapper) Head() (common.Hash, []*big.Int) { return w.peer.Head() }
func (w *lightPeerWrapper) RequestHeadersByHash(h common.Hash, amount int, skip int, reverse bool) error {
return w.peer.RequestHeadersByHash(h, amount, skip, reverse)
}
Expand Down
Loading

0 comments on commit a0c397a

Please sign in to comment.