Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Chan andrewkkchan

View GitHub Profile
@andrewkkchan
andrewkkchan / chain.go
Created Jun 23, 2021
Chain at Hyper ledger Fabric
View chain.go
type chain struct {
support consensus.ConsenterSupport
sendChan chan *message
exitChan chan struct{}
}
@andrewkkchan
andrewkkchan / Order.go
Created Jun 23, 2021
Order function at Hyper ledger Fabric
View Order.go
// 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 Jun 23, 2021
Order Chain at Hyper ledger Fabric
View OrderChain.go
// 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 Jun 23, 2021
IncrementExtraNonce at BitCoin Core
View IncrementExtraNonce.cpp
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 Jun 23, 2021
BlockHeader of BitCoin Core
View CBlockHeader.cpp
class CBlockHeader
{
public:
// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint32_t nTime;
uint32_t nBits;
uint32_t nNonce;