Skip to content

Commit e414b34

Browse files
authored
chore: fix SnapSyncWithBlobs UT issues; (bnb-chain#3362)
1 parent d4567d1 commit e414b34

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

eth/handler_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ func newTestParliaHandlerAfterCancun(t *testing.T, config *params.ChainConfig, m
300300
Alloc: types.GenesisAlloc{testAddr: {Balance: new(big.Int).SetUint64(10 * params.Ether)}},
301301
}
302302
engine := &mockParlia{}
303-
chain, _ := core.NewBlockChain(db, gspec, engine, nil)
303+
cfg := core.DefaultConfig()
304+
cfg.StateScheme = rawdb.PathScheme
305+
chain, _ := core.NewBlockChain(db, gspec, engine, cfg)
304306
signer := types.LatestSigner(config)
305307

306308
_, bs, _ := core.GenerateChainWithGenesis(gspec, engine, int(preCancunBlks+postCancunBlks), func(i int, gen *core.BlockGen) {

eth/sync_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func testChainSyncWithBlobs(t *testing.T, mode downloader.SyncMode, preCancunBlk
138138
// Sync up the two handlers via both `eth` and `snap`
139139
caps := []p2p.Cap{{Name: "eth", Version: ethVer}, {Name: "snap", Version: snapVer}}
140140

141-
emptyPipeEth, fullPipeEth := p2p.MsgPipe()
141+
emptyPipeEth, fullPipeEth := p2p.MsgPipe(true)
142142
defer emptyPipeEth.Close()
143143
defer fullPipeEth.Close()
144144

@@ -154,7 +154,7 @@ func testChainSyncWithBlobs(t *testing.T, mode downloader.SyncMode, preCancunBlk
154154
return eth.Handle((*ethHandler)(full.handler), peer)
155155
})
156156

157-
emptyPipeSnap, fullPipeSnap := p2p.MsgPipe()
157+
emptyPipeSnap, fullPipeSnap := p2p.MsgPipe(true)
158158
defer emptyPipeSnap.Close()
159159
defer fullPipeSnap.Close()
160160

p2p/message.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,21 @@ func (r *eofSignal) Read(buf []byte) (int, error) {
152152
// MsgPipe creates a message pipe. Reads on one end are matched
153153
// with writes on the other. The pipe is full-duplex, both ends
154154
// implement MsgReadWriter.
155-
func MsgPipe() (*MsgPipeRW, *MsgPipeRW) {
155+
func MsgPipe(args ...any) (*MsgPipeRW, *MsgPipeRW) {
156+
noBlock := false
157+
if len(args) > 0 {
158+
noBlock = args[0].(bool)
159+
}
160+
c1, c2 := make(chan Msg), make(chan Msg)
161+
if noBlock {
162+
c1 = make(chan Msg, 1)
163+
c2 = make(chan Msg, 1)
164+
}
156165
var (
157-
c1, c2 = make(chan Msg), make(chan Msg)
158166
closing = make(chan struct{})
159167
closed = new(atomic.Bool)
160-
rw1 = &MsgPipeRW{c1, c2, closing, closed}
161-
rw2 = &MsgPipeRW{c2, c1, closing, closed}
168+
rw1 = &MsgPipeRW{c1, c2, closing, closed, noBlock}
169+
rw2 = &MsgPipeRW{c2, c1, closing, closed, noBlock}
162170
)
163171
return rw1, rw2
164172
}
@@ -173,6 +181,7 @@ type MsgPipeRW struct {
173181
r <-chan Msg
174182
closing chan struct{}
175183
closed *atomic.Bool
184+
noBlock bool
176185
}
177186

178187
// WriteMsg sends a message on the pipe.
@@ -183,6 +192,9 @@ func (p *MsgPipeRW) WriteMsg(msg Msg) error {
183192
msg.Payload = &eofSignal{msg.Payload, msg.Size, consumed}
184193
select {
185194
case p.w <- msg:
195+
if p.noBlock {
196+
return nil
197+
}
186198
if msg.Size > 0 {
187199
// wait for payload read or discard
188200
select {

0 commit comments

Comments
 (0)