koinos / koinos-p2p

The p2p microservice orchestrates the distribution of blocks and transactions between peers.
MIT License
6 stars 4 forks source link

Prioritize Block Applications #229

Closed mvandeberg closed 1 year ago

mvandeberg commented 1 year ago

As a Koinos node operator, I want my p2p node to prioritize applying blocks to prevent my node from disconnecting from peers and forking during times of increased load.

The block applicator should be extended to handle transactions. However, transactions do not need to be stored, so the implementation is straight forward. Transaction applications requests need to be added to a channel. The block applicator go routine that consumes block application requests should also consume transaction requests. But by placing the block application channel first, it will prioritize those message first. Consult this example on how to implement this beheavior:

func listener(urgentJobs <-chan int, trivialJobs <-chan int) {
    for {
        select  {
        case job := <-urgentJobs:
            urgent(job)
        default:
            select {
            case job := <-urgentJobs:
                urgent(job)
            case job := <-trivialJobs:
                trivial(job)
            }
        }
    }
}

(http://www.inanzzz.com/index.php/post/k29t/implementing-priority-select-within-channels-in-golang)