Skip to content

Instantly share code, notes, and snippets.

View andrewkkchan's full-sized avatar

Andrew Koon Kit Chan andrewkkchan

View GitHub Profile
@andrewkkchan
andrewkkchan / chain.go
Created June 23, 2021 14:47
Chain at Hyper ledger Fabric
type chain struct {
support consensus.ConsenterSupport
sendChan chan *message
exitChan chan struct{}
}
@andrewkkchan
andrewkkchan / Order.go
Created June 23, 2021 14:47
Order function at Hyper ledger Fabric
// Order accepts normal messages for ordering
func (ch *chain) Order(env *cb.Envelope, configSeq uint64) error {
select {
case ch.sendChan <- &message{
configSeq: configSeq,
normalMsg: env,
}:
return nil
case <-ch.exitChan:
return fmt.Errorf("Exiting")
@andrewkkchan
andrewkkchan / OrderChain.go
Created June 23, 2021 14:46
Order Chain at Hyper ledger Fabric
// Chain defines a way to inject messages for ordering.
// Note, that in order to allow flexibility in the implementation, it is the responsibility of the implementer
// to take the ordered messages, send them through the blockcutter.Receiver supplied via HandleChain to cut blocks,
// and ultimately write the ledger also supplied via HandleChain. This design allows for two primary flows
// 1. Messages are ordered into a stream, the stream is cut into blocks, the blocks are committed (solo, kafka)
// 2. Messages are cut into blocks, the blocks are ordered, then the blocks are committed (sbft)
type Chain interface {
// Order accepts a message which has been processed at a given configSeq.
// If the configSeq advances, it is the responsibility of the consenter
// to revalidate and potentially discard the message
@andrewkkchan
andrewkkchan / IncrementExtraNonce.cpp
Created June 23, 2021 14:45
IncrementExtraNonce at BitCoin Core
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
{
// Update nExtraNonce
static uint256 hashPrevBlock;
if (hashPrevBlock != pblock->hashPrevBlock)
{
nExtraNonce = 0;
hashPrevBlock = pblock->hashPrevBlock;
}
++nExtraNonce;
@andrewkkchan
andrewkkchan / CBlockHeader.cpp
Created June 23, 2021 14:44
BlockHeader of BitCoin Core
class CBlockHeader
{
public:
// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;