Skip to content

Commit

Permalink
fix: change requests
Browse files Browse the repository at this point in the history
- put store reader before message channel
- add comment private for ConsumptionBlocks
- move ConsumptionBlocks to down of struct config
- move handle committed block after write batch
  • Loading branch information
Ja7ad committed Oct 19, 2024
1 parent c6cffcb commit c7dbcf1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config,
return nil, err
}

txPool := txpool.NewTxPool(conf.TxPool, messageCh, str)
txPool := txpool.NewTxPool(conf.TxPool, str, messageCh)

st, err := state.LoadOrNewState(genDoc, valKeys, str, txPool, eventCh)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@ func (st *state) CommitBlock(blk *block.Block, cert *certificate.BlockCertificat

st.store.SaveBlock(blk, cert)

// Remove transactions from pool and update consumption
if errHandleCommittedBlk := st.txPool.HandleCommittedBlock(blk); errHandleCommittedBlk != nil {
return errHandleCommittedBlk
}

if err := st.store.WriteBatch(); err != nil {
st.logger.Panic("unable to update state", "error", err)
}

// Remove transactions from pool and update consumption
if err := st.txPool.HandleCommittedBlock(blk); err != nil {
return err
}

st.logger.Info("new block committed", "block", blk, "round", cert.Round())

st.evaluateSortition()
Expand Down
4 changes: 2 additions & 2 deletions txpool/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

type Config struct {
MaxSize int `toml:"max_size"`
ConsumptionBlocks uint32 `toml:"-"`
Fee *FeeConfig `toml:"fee"`
ConsumptionBlocks uint32 `toml:"-"` // Private configs
}

type FeeConfig struct {
Expand All @@ -19,8 +19,8 @@ type FeeConfig struct {
func DefaultConfig() *Config {
return &Config{
MaxSize: 1000,
ConsumptionBlocks: 8640,
Fee: DefaultFeeConfig(),
ConsumptionBlocks: 8640,
}
}

Expand Down
4 changes: 2 additions & 2 deletions txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type txPool struct {
logger *logger.SubLogger
}

func NewTxPool(conf *Config, broadcastCh chan message.Message, storeReader store.Reader) TxPool {
func NewTxPool(conf *Config, storeReader store.Reader, broadcastCh chan message.Message) TxPool {
pools := make(map[payload.Type]pool)
pools[payload.TypeTransfer] = newPool(conf.transferPoolSize(), conf.minFee())
pools[payload.TypeBond] = newPool(conf.bondPoolSize(), conf.minFee())
Expand Down Expand Up @@ -185,8 +185,8 @@ func (p *txPool) handleDecreaseConsumption(height uint32) error {
// Decrease the consumption by the size of the transaction
v -= uint32(trx.SerializeSize())

// If the new value is zero, remove the signer from the consumptionMap
if v == 0 {
// If the new value is zero, remove the signer from the consumptionMap
delete(p.consumptionMap, signer)
} else {
// Otherwise, update the map with the new value
Expand Down
2 changes: 1 addition & 1 deletion txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func setup(t *testing.T) *testData {
sb := sandbox.MockingSandbox(ts)
config := testConfig()
mockStore := store.MockingStore(ts)
p := NewTxPool(config, ch, mockStore)
p := NewTxPool(config, mockStore, ch)
p.SetNewSandboxAndRecheck(sb)
pool := p.(*txPool)
assert.NotNil(t, pool)
Expand Down

0 comments on commit c7dbcf1

Please sign in to comment.