fibercrypto / fibercrypto/skycoin

Refactor Daemon to use instance of Exchange

Open
#2,267 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Daemon is a bit messy because it deals both with networking and with local copy of blockchain.

All implementation of networking (like gnet connection pool and messages, connection state management, PEX) can be abstracted away via the following interface:

```go
// BlockchainExchange
type BlockchainExchange interface {
AnnounceTransactions([]cipher.SHA256) error
AnnounceBlocks([]cipher.SHA256) error
RequestTransactions(cipher.PubKey, []cipher.SHA256) error
RequestBlocks(cipher.PubKey, []cipher.SHA256) error
SendTransactions(cipher.PubKey, []coin.Transaction) error
SendBlocks(cipher.PubKey, []coin.SignedBlock) error
Events() <-chan interface{}
}
```

Then duty of Daemon will become only dealing with local copy of blockchain by:
- periodically calling some methods of Exhcnage
- handling incoming events (which will involve calling methods of Exchange)

Here is rough list of events, that can be received by Daemon form channel, returned by Events() method is:

```go
// PeerConnectEvent
PeerConnectEvent struct {
PubKey cipher.PubKey
}

// PeerDisconnectEvent
PeerDisconnectEvent struct {
PubKey cipher.PubKey
}

// TransactionAnnouncementEvent
TransactionAnnouncementEvent struct {
Peer cipher.PubKey
TxnHashes []cipher.SHA256
}

// BlockAnnouncementEvent
BlockAnnouncementEvent struct {
Peer cipher.PubKey
MaxBlockSeqNo uint64
}

// TransactionRequestEvent
TransactionRequestEvent struct {
Peer cipher.PubKey
TxnHashes []cipher.SHA256
}

// BlockRequestEvent
BlockRequestEvent struct {
Peer cipher.PubKey
LastBlock uint64
BlockCount uint64
}

// TransactionDataEvent
TransactionDataEvent struct {
Peer cipher.PubKey
Transactions []coin.Transaction
}

// BlockDataEvent
BlockDataEvent struct {
Peer cipher.PubKey
Blocks []coin.SignedBlock
}
```

Such design will help to reuse networking part of gossip protocol in projects which deal with local copy of blockchain in different way.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting Daemon's networking responsibilities and the proposed BlockchainExchange interface. Trace how connection management, PEX, announcements, requests, and Events() currently interact with the local blockchain copy. Done means Daemon handles local blockchain logic while networking is exposed through the exchange interface, with the listed events and methods covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems, networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.