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 a Shard Transaction Generator #153

Closed
rauljordan opened this issue Jun 6, 2018 · 3 comments · Fixed by #171
Closed

Implement a Shard Transaction Generator #153

rauljordan opened this issue Jun 6, 2018 · 3 comments · Fixed by #171
Milestone

Comments

@rauljordan
Copy link
Contributor

Now that #149 is merged, we can create a simple shard tx generator as a service attached to ShardEthereum from sharding/node/backend.go that publishes []*types.Transaction data to a go channel.

The proposer service will need this in order to process these incoming transactions into serialized blobs that will then be packaged into collations.

@rauljordan rauljordan added this to the Ruby milestone Jun 6, 2018
@rauljordan rauljordan self-assigned this Jun 7, 2018
@rauljordan
Copy link
Contributor Author

Hey @rawfalafel, as I mentioned, I started on this issue but happy for you to take over if you want.

The idea was that I added an event feed to the shard txpool as follows:

in sharding/txpool/service.go

// ShardTXPool handles a transaction pool for a sharded system.
type ShardTXPool struct {
	p2p              sharding.ShardP2P
	transactionsFeed *event.Feed
}

// NewShardTXPool creates a new observer instance.
func NewShardTXPool(p2p sharding.ShardP2P) (*ShardTXPool, error) {
	return &ShardTXPool{p2p: p2p, transactionsFeed: new(event.Feed)}, nil
}

// Start the main routine for a shard transaction pool.
func (pool *ShardTXPool) Start() error {
	log.Info("Starting shard txpool service")
	go pool.generateTestTransactions()
	return nil
}

func (pool *ShardTXPool) TransactionsFeed() *event.Feed {
	return pool.transactionsFeed
}

func (pool *ShardTXPool) generateTestTransactions() {
	for {
		nsent := pool.transactionsFeed.Send(1)
		log.Info(fmt.Sprintf("Sent transaction to %d subscribers", nsent))
		time.Sleep(time.Second)
	}
}

and then in the proposer subpackage, I subscribed to this feed via a for, select block:

in sharding/proposer/service.go

// Start the main loop for proposing collations.
func (p *Proposer) Start() error {
	log.Info("Starting proposer service")
	go p.subscribeTransactions()
	return nil
}

func (p *Proposer) subscribeTransactions() {
	// Subscribes to incoming transactions from the txpool via the shardp2p network.
	for {
		subchan := make(chan int)
		sub := p.txpool.TransactionsFeed().Subscribe(subchan)
		// 10 second time out for the subscription.
		timeout := time.NewTimer(10 * time.Second)
		select {
		case v := <-subchan:
			log.Info(fmt.Sprintf("Received transaction with id: %d", v))
		case <-timeout.C:
			log.Error("Receive timeout")
		}

		sub.Unsubscribe()
		select {
		case _, ok := <-sub.Err():
			if ok {
				log.Error("Channel not closed after unsubscribe")
			}
		case <-timeout.C:
			log.Error("Unsubscribe timeout")
		}
	}
}

Right now I just used an int for the channel but we can make this system more elaborate by generating a variety of different transactions. The PR should also include tests and a nicer way to generate them at random intervals + handling timeouts. Let me know if you are interested. I started this on my personal branch but happy for you to take the initial code from there and take over.

@rauljordan rauljordan removed their assignment Jun 7, 2018
@rauljordan
Copy link
Contributor Author

Assigning to @rawfalafel (Yutaro)

@rawfalafel
Copy link
Contributor

Pulled in your branch and taking a look now. Thanks @rauljordan !

Redidacove pushed a commit to Redidacove/prysm that referenced this issue Aug 13, 2024
* dev update week 3

* style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants