mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
b05ffc909d
This PR contains 3 fixes for interaction between the Bor mining loop and the TX pool which where causing the regular creation of blocks with zero transactions. * Mining/Tx pool block synchronization The synchronization of the tx pool between the sync loop and the mining loop has been changed so that both are triggered by the same event and synchronized via a sync.Cond rather than a polling loop with a hard coded loop limit. This means that mining now waits for the pool to be updated from the previous block before it starts the mining process. * Txpool Startup consolidated into its MainLoop Previously the tx pool start process was dynamically triggered at various points in the code. This has all now been moved to the start of the main loop. This is necessary to avoid a timing hole which can leave the mining loop hanging waiting for a previously block broadcast which it missed due to its delay start. * Mining listens for block broadcast to avoid duplicate mining operations The mining loop for bor has a recommit timer in case blocks re not produced on time. However in the case of sprint transitions where the seal publication is delayed this can lead to duplicate block production. This is suppressed by introducing a `waiting` state which is exited upon the block being broadcast from the sealing operation.
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
/*
|
|
Copyright 2021 Erigon contributors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package mmap
|
|
|
|
import (
|
|
"os"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
const MaxMapSize = 0xFFFFFFFFFFFF
|
|
|
|
func Mmap(f *os.File, size int) ([]byte, *[MaxMapSize]byte, error) {
|
|
// Open a file mapping handle.
|
|
sizelo := uint32(size >> 32)
|
|
sizehi := uint32(size) & 0xffffffff
|
|
h, errno := windows.CreateFileMapping(windows.Handle(f.Fd()), nil, windows.PAGE_READONLY, sizelo, sizehi, nil)
|
|
if h == 0 {
|
|
return nil, nil, os.NewSyscallError("CreateFileMapping", errno)
|
|
}
|
|
|
|
// Create the memory map.
|
|
addr, errno := windows.MapViewOfFile(h, windows.FILE_MAP_READ, 0, 0, uintptr(size))
|
|
if addr == 0 {
|
|
return nil, nil, os.NewSyscallError("MapViewOfFile", errno)
|
|
}
|
|
|
|
// Close mapping handle.
|
|
if err := windows.CloseHandle(h); err != nil {
|
|
return nil, nil, os.NewSyscallError("CloseHandle", err)
|
|
}
|
|
|
|
// Convert to a byte array.
|
|
mmapHandle2 := ((*[MaxMapSize]byte)(unsafe.Pointer(addr)))
|
|
return mmapHandle2[:size], mmapHandle2, nil
|
|
}
|
|
|
|
func MadviseSequential(mmapHandle1 []byte) error { return nil }
|
|
func MadviseNormal(mmapHandle1 []byte) error { return nil }
|
|
func MadviseWillNeed(mmapHandle1 []byte) error { return nil }
|
|
func MadviseRandom(mmapHandle1 []byte) error { return nil }
|
|
|
|
func Munmap(_ []byte, mmapHandle2 *[MaxMapSize]byte) error {
|
|
if mmapHandle2 == nil {
|
|
return nil
|
|
}
|
|
|
|
addr := (uintptr)(unsafe.Pointer(&mmapHandle2[0]))
|
|
if err := windows.UnmapViewOfFile(addr); err != nil {
|
|
return os.NewSyscallError("UnmapViewOfFile", err)
|
|
}
|
|
return nil
|
|
}
|