Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Message Pool #121

Closed
5 tasks
dutterbutter opened this issue Dec 21, 2019 · 0 comments · Fixed by #449
Closed
5 tasks

Implement Message Pool #121

dutterbutter opened this issue Dec 21, 2019 · 0 comments · Fixed by #449
Assignees
Labels
Priority: 2 - High Very important and should be addressed ASAP

Comments

@dutterbutter
Copy link
Contributor

The Message Pool is a subsystem in the Filecoin blockchain system. The message pool acts as the interface between Filecoin nodes and a peer-to-peer network used for off-chain message transmission. It is used by nodes to maintain a set of messages to transmit to the Filecoin VM (for “on-chain” execution).

Spec reference:

Existing implementations for reference:

Needs access to the following subsystems:

  • StateTree
  • Messages mined into blocks
  • MessagePubSub
  • SignedMessages

Although the spec is very incomplete you can expect the following data structures/methods:

  • struct MessagePool and constructor
  • add_new_message
  • find_messages //returns set of messages in mempool
  • profitable_msgs // returns messages most profitable to mine for the miner
  • MessageQuery struct and constructor

From Lotus implementation:

Pool struct

type MessagePool struct {
	lk sync.Mutex

	closer  chan struct{}
	repubTk *time.Ticker

	localAddrs map[address.Address]struct{}

	pending map[address.Address]*msgSet

	curTsLk sync.Mutex // DO NOT LOCK INSIDE lk
	curTs   *types.TipSet

	api Provider

	minGasPrice types.BigInt

	maxTxPoolSize int

	blsSigCache *lru.TwoQueueCache

	changes *lps.PubSub

	localMsgs datastore.Datastore
}

add_new_message:

type msgSet struct {
	msgs      map[uint64]*types.SignedMessage
	nextNonce uint64
}

func newMsgSet() *msgSet {
	return &msgSet{
		msgs: make(map[uint64]*types.SignedMessage),
	}
}

func (ms *msgSet) add(m *types.SignedMessage) error {
	if len(ms.msgs) == 0 || m.Message.Nonce >= ms.nextNonce {
		ms.nextNonce = m.Message.Nonce + 1
	}
	if _, has := ms.msgs[m.Message.Nonce]; has {
		if m.Cid() != ms.msgs[m.Message.Nonce].Cid() {
			log.Error("Add with duplicate nonce")
			return xerrors.Errorf("message to %s with nonce %d already in mpool")
		}
	}
	ms.msgs[m.Message.Nonce] = m

	return nil
}
@dutterbutter dutterbutter added Blockchain Priority: 4 - Low Limited impact and can be implemented at any time Type: Epic A feature or collection of issues that achieve a greater goal labels Dec 21, 2019
@austinabell austinabell removed the Type: Epic A feature or collection of issues that achieve a greater goal label Mar 11, 2020
@dutterbutter dutterbutter added Priority: 2 - High Very important and should be addressed ASAP and removed Priority: 4 - Low Limited impact and can be implemented at any time Status: On Ice labels May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: 2 - High Very important and should be addressed ASAP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants