Skip to content

Commit f176688

Browse files
committed
chore: remove Block and Hooks type aliases
1 parent f2b4bee commit f176688

File tree

8 files changed

+32
-38
lines changed

8 files changed

+32
-38
lines changed

block.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515
"go.uber.org/zap"
1616
)
1717

18-
type Block = blocks.Block
19-
20-
func (vm *VM) AcceptBlock(ctx context.Context, b *Block) error {
18+
func (vm *VM) AcceptBlock(ctx context.Context, b *blocks.Block) error {
2119
batch := vm.db.NewBatch()
2220
rawdb.WriteBlock(batch, b.Block)
2321
rawdb.WriteCanonicalHash(batch, b.Hash(), b.NumberU64())
@@ -66,7 +64,7 @@ func (vm *VM) AcceptBlock(ctx context.Context, b *Block) error {
6664
return vm.blocks.Use(ctx, func(bm blockMap) error {
6765
// Same rationale as the invariant described in [Block]. Praised be the
6866
// GC!
69-
prune := func(b *Block) {
67+
prune := func(b *blocks.Block) {
7068
delete(bm, b.Hash())
7169
vm.logger().Debug(
7270
"Pruning settled block",
@@ -93,12 +91,12 @@ func (vm *VM) AcceptBlock(ctx context.Context, b *Block) error {
9391
})
9492
}
9593

96-
func (vm *VM) RejectBlock(ctx context.Context, b *Block) error {
94+
func (vm *VM) RejectBlock(ctx context.Context, b *blocks.Block) error {
9795
// TODO(arr4n) add the transactions back to the mempool if necessary.
9896
return nil
9997
}
10098

101-
func (vm *VM) VerifyBlock(ctx context.Context, b *Block) error {
99+
func (vm *VM) VerifyBlock(ctx context.Context, b *blocks.Block) error {
102100
parent, err := vm.GetBlock(ctx, ids.ID(b.ParentHash()))
103101
if err != nil {
104102
return fmt.Errorf("block parent %#x not found (presumed height %d)", b.ParentHash(), b.Height()-1)

builder.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
"go.uber.org/zap"
1919
)
2020

21-
func (vm *VM) buildBlock(ctx context.Context, timestamp uint64, parent *Block) (*Block, error) {
21+
func (vm *VM) buildBlock(ctx context.Context, timestamp uint64, parent *blocks.Block) (*blocks.Block, error) {
2222
block, err := sink.FromPriorityMutex(
2323
ctx, vm.mempool, sink.MaxPriority,
24-
func(_ <-chan sink.Priority, pool *queue.Priority[*pendingTx]) (*Block, error) {
24+
func(_ <-chan sink.Priority, pool *queue.Priority[*pendingTx]) (*blocks.Block, error) {
2525
return vm.buildBlockWithCandidateTxs(timestamp, parent, pool)
2626
},
2727
)
@@ -43,7 +43,7 @@ var (
4343
errNoopBlock = errors.New("block does not settle state nor include transactions")
4444
)
4545

46-
func (vm *VM) buildBlockWithCandidateTxs(timestamp uint64, parent *Block, candidateTxs queue.Queue[*pendingTx]) (*Block, error) {
46+
func (vm *VM) buildBlockWithCandidateTxs(timestamp uint64, parent *blocks.Block, candidateTxs queue.Queue[*pendingTx]) (*blocks.Block, error) {
4747
if timestamp < parent.Time() {
4848
return nil, fmt.Errorf("block at time %d before parent at %d", timestamp, parent.Time())
4949
}
@@ -106,8 +106,8 @@ func (vm *VM) buildBlockWithCandidateTxs(timestamp uint64, parent *Block, candid
106106
return blocks.New(ethB, parent, toSettle, vm.logger())
107107
}
108108

109-
func (vm *VM) buildBlockOnHistory(lastSettled, parent *Block, timestamp uint64, candidateTxs queue.Queue[*pendingTx]) (_ types.Transactions, _ gas.Gas, retErr error) {
110-
var history []*Block
109+
func (vm *VM) buildBlockOnHistory(lastSettled, parent *blocks.Block, timestamp uint64, candidateTxs queue.Queue[*pendingTx]) (_ types.Transactions, _ gas.Gas, retErr error) {
110+
var history []*blocks.Block
111111
for b := parent; b.ID() != lastSettled.ID(); b = b.ParentBlock() {
112112
history = append(history, b)
113113
}
@@ -209,7 +209,7 @@ func errIsOneOf(err error, targets ...error) bool {
209209
return false
210210
}
211211

212-
func (vm *VM) lastBlockToSettleAt(timestamp uint64, parent *Block) (*Block, bool) {
212+
func (vm *VM) lastBlockToSettleAt(timestamp uint64, parent *blocks.Block) (*blocks.Block, bool) {
213213
settleAt := intmath.BoundedSubtract(timestamp, stateRootDelaySeconds, vm.last.synchronousTime)
214214
return blocks.LastToSettleAt(settleAt, parent)
215215
}

db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (vm *VM) recoverFromDB(ctx context.Context, chainConfig *params.ChainConfig
103103

104104
return vm.blocks.Replace(ctx, func(blockMap) (blockMap, error) {
105105
byID := make(blockMap)
106-
byNum := make(map[uint64]*Block)
106+
byNum := make(map[uint64]*blocks.Block)
107107

108108
for i, num := range nums {
109109
hash := hashes[i]

harness.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
"github.com/ava-labs/libevm/core/rawdb"
1313
"github.com/ava-labs/libevm/core/state"
1414
"github.com/ava-labs/strevm/adaptor"
15+
"github.com/ava-labs/strevm/blocks"
16+
"github.com/ava-labs/strevm/hook"
1517
)
1618

1719
func init() {
1820
var (
1921
vm *SinceGenesis
20-
_ snowcommon.VM = vm
21-
_ adaptor.ChainVM[*Block] = vm
22+
_ snowcommon.VM = vm
23+
_ adaptor.ChainVM[*blocks.Block] = vm
2224
)
2325
}
2426

@@ -30,7 +32,7 @@ func init() {
3032
type SinceGenesis struct {
3133
*VM // Populated by [SinceGenesis.Initialize]
3234
// Propagated to [Config]
33-
Hooks Hooks
35+
Hooks hook.Points
3436
Now func() time.Time
3537
}
3638

hooks.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

rpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (b *ethAPIBackend) resolveBlockNumber(num rpc.BlockNumber) (uint64, common.
133133

134134
// blockNumAndHash always returns a nil error; the signature is for convenience
135135
// when used in [ethAPIBackend.resolveBlockNumber].
136-
func (*ethAPIBackend) blockNumAndHash(block *atomic.Pointer[Block]) (uint64, common.Hash, error) {
136+
func (*ethAPIBackend) blockNumAndHash(block *atomic.Pointer[blocks.Block]) (uint64, common.Hash, error) {
137137
b := block.Load()
138138
return b.NumberU64(), b.Hash(), nil
139139
}

sae_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestBasicE2E(t *testing.T) {
123123
assert.Nil(t, block.LastSettled(), "last settled")
124124
assert.True(t, block.Executed(), "executed")
125125

126-
for k, ptr := range map[string]*atomic.Pointer[Block]{
126+
for k, ptr := range map[string]*atomic.Pointer[blocks.Block]{
127127
"accepted": &vm.last.accepted,
128128
"executed": &vm.last.executed,
129129
"settled": &vm.last.settled,
@@ -192,8 +192,8 @@ func TestBasicE2E(t *testing.T) {
192192
require.NoErrorf(t, err, "%T.SubscribeFilterLogs()", err)
193193

194194
var (
195-
acceptedBlocks []*Block
196-
blockWithLastTx *Block
195+
acceptedBlocks []*blocks.Block
196+
blockWithLastTx *blocks.Block
197197
waitingForExecution int
198198
)
199199
start := time.Now()
@@ -575,7 +575,7 @@ func cmpVMs(ctx context.Context, tb testing.TB) cmp.Options {
575575
require.NoError(tb, err)
576576
return bm
577577
}),
578-
cmp.Transformer("atomic_block", func(p atomic.Pointer[Block]) *Block {
578+
cmp.Transformer("atomic_block", func(p atomic.Pointer[blocks.Block]) *blocks.Block {
579579
return p.Load()
580580
}),
581581
cmp.Transformer("state_dump", func(db *state.StateDB) state.Dump {

vm.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/ava-labs/libevm/params"
2424
"github.com/ava-labs/libevm/rlp"
2525
"github.com/ava-labs/strevm/blocks"
26+
"github.com/ava-labs/strevm/hook"
2627
"github.com/ava-labs/strevm/queue"
2728
"github.com/ava-labs/strevm/saexec"
2829
)
@@ -35,13 +36,13 @@ type VM struct {
3536
snowCtx *snow.Context
3637
snowcommon.AppHandler
3738
toEngine chan<- snowcommon.Message
38-
hooks Hooks
39+
hooks hook.Points
3940
now func() time.Time
4041

4142
consensusState utils.Atomic[snow.State]
4243

4344
blocks sink.Mutex[blockMap]
44-
preference atomic.Pointer[Block]
45+
preference atomic.Pointer[blocks.Block]
4546
last last
4647

4748
db ethdb.Database
@@ -56,15 +57,15 @@ type VM struct {
5657
}
5758

5859
type (
59-
blockMap map[common.Hash]*Block
60+
blockMap map[common.Hash]*blocks.Block
6061
last struct {
6162
synchronousTime uint64
62-
accepted, executed, settled atomic.Pointer[Block]
63+
accepted, executed, settled atomic.Pointer[blocks.Block]
6364
}
6465
)
6566

6667
type Config struct {
67-
Hooks Hooks
68+
Hooks hook.Points
6869
ChainConfig *params.ChainConfig
6970
DB ethdb.Database
7071
// At the point of upgrade from synchronous to asynchronous execution, the
@@ -129,7 +130,7 @@ func New(ctx context.Context, c Config) (*VM, error) {
129130
return vm, nil
130131
}
131132

132-
func (vm *VM) newBlock(b *types.Block, parent, lastSettled *Block) (*Block, error) {
133+
func (vm *VM) newBlock(b *types.Block, parent, lastSettled *blocks.Block) (*blocks.Block, error) {
133134
return blocks.New(b, parent, lastSettled, vm.logger())
134135
}
135136

@@ -186,8 +187,8 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]http.Handler, error) {
186187
}, nil
187188
}
188189

189-
func (vm *VM) GetBlock(ctx context.Context, blkID ids.ID) (*Block, error) {
190-
b, err := sink.FromMutex(ctx, vm.blocks, func(blocks blockMap) (*Block, error) {
190+
func (vm *VM) GetBlock(ctx context.Context, blkID ids.ID) (*blocks.Block, error) {
191+
b, err := sink.FromMutex(ctx, vm.blocks, func(blocks blockMap) (*blocks.Block, error) {
191192
if b, ok := blocks[common.Hash(blkID)]; ok {
192193
return b, nil
193194
}
@@ -216,7 +217,7 @@ func (vm *VM) GetBlock(ctx context.Context, blkID ids.ID) (*Block, error) {
216217
return vm.newBlock(ethB, nil, nil)
217218
}
218219

219-
func (vm *VM) ParseBlock(ctx context.Context, blockBytes []byte) (*Block, error) {
220+
func (vm *VM) ParseBlock(ctx context.Context, blockBytes []byte) (*blocks.Block, error) {
220221
b := new(types.Block)
221222
if err := rlp.DecodeBytes(blockBytes, b); err != nil {
222223
return nil, err
@@ -227,7 +228,7 @@ func (vm *VM) ParseBlock(ctx context.Context, blockBytes []byte) (*Block, error)
227228
return vm.newBlock(b, nil, nil)
228229
}
229230

230-
func (vm *VM) BuildBlock(ctx context.Context) (*Block, error) {
231+
func (vm *VM) BuildBlock(ctx context.Context) (*blocks.Block, error) {
231232
return vm.buildBlock(ctx, uint64(vm.now().Unix()), vm.preference.Load())
232233
}
233234

0 commit comments

Comments
 (0)