Upgrade to consensus v3.6.4, store and expose pool block metadata on json/blob
This commit is contained in:
parent
8467fbb339
commit
603241d884
105
api.go
105
api.go
|
@ -17,15 +17,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func addPoolBlockMetadata(writer http.ResponseWriter, b *sidechain.PoolBlock) {
|
||||
|
||||
writer.Header().Add("X-Block-Metadata-Local-Time", b.Metadata.LocalTime.Format(time.RFC3339Nano))
|
||||
writer.Header().Add("X-Block-Metadata-Address-Port", b.Metadata.AddressPort.String())
|
||||
writer.Header().Add("X-Block-Metadata-Peer-Id", strconv.FormatUint(b.Metadata.PeerId, 10))
|
||||
writer.Header().Add("X-Block-Metadata-Software-Id", strconv.FormatUint(uint64(b.Metadata.SoftwareId), 10))
|
||||
writer.Header().Add("X-Block-Metadata-Software-Version", strconv.FormatUint(uint64(b.Metadata.SoftwareVersion), 10))
|
||||
}
|
||||
|
||||
func getServerMux(instance *P2Pool) *mux.Router {
|
||||
|
||||
serveMux := mux.NewRouter()
|
||||
|
@ -327,11 +318,10 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result = append(result, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
|
||||
addPoolBlockMetadata(writer, b)
|
||||
}
|
||||
}
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
@ -352,8 +342,7 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
result.Error = err.Error()
|
||||
} else {
|
||||
result.Blob = blob
|
||||
|
||||
addPoolBlockMetadata(writer, b)
|
||||
result.Metadata = b.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,8 +374,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Chain = append(result.Chain, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -398,8 +388,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Uncles = append(result.Uncles, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -431,8 +422,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Chain = append(result.Chain, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -444,8 +436,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Uncles = append(result.Uncles, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -479,8 +472,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Chain = append(result.Chain, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -492,14 +486,13 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Uncles = append(result.Uncles, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
addPoolBlockMetadata(writer, tip)
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = EncodeJson(request, writer, result)
|
||||
|
@ -522,8 +515,7 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
result.Error = err.Error()
|
||||
} else {
|
||||
result.Blob = blob
|
||||
|
||||
addPoolBlockMetadata(writer, b)
|
||||
result.Metadata = b.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -624,8 +616,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Chain = append(result.Chain, P2PoolBinaryBlockResult{
|
||||
Version: int(e.Block.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(e.Block.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: e.Block.Metadata,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -644,8 +637,9 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result.Uncles = append(result.Uncles, P2PoolBinaryBlockResult{
|
||||
Version: int(u.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(u.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: u.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -745,11 +739,10 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
|
||||
addPoolBlockMetadata(writer, b)
|
||||
|
||||
result = append(result, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -777,12 +770,10 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
Error: err.Error(),
|
||||
})
|
||||
} else {
|
||||
|
||||
addPoolBlockMetadata(writer, b)
|
||||
|
||||
result = append(result, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -799,11 +790,6 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
serveMux.HandleFunc("/archive/light_blocks_by_main_height/{height:[0-9]+}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
if height, err := strconv.ParseUint(mux.Vars(request)["height"], 10, 0); err == nil {
|
||||
if blocks := archiveCache.LoadByMainChainHeight(height); len(blocks) > 0 {
|
||||
|
||||
for _, b := range blocks {
|
||||
addPoolBlockMetadata(writer, b)
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = EncodeJson(request, writer, blocks)
|
||||
|
@ -826,11 +812,6 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
serveMux.HandleFunc("/archive/light_blocks_by_side_height/{height:[0-9]+}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
if height, err := strconv.ParseUint(mux.Vars(request)["height"], 10, 0); err == nil {
|
||||
if blocks := archiveCache.LoadBySideChainHeight(height); len(blocks) > 0 {
|
||||
|
||||
for _, b := range blocks {
|
||||
addPoolBlockMetadata(writer, b)
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = EncodeJson(request, writer, blocks)
|
||||
|
@ -852,11 +833,6 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
serveMux.HandleFunc("/archive/light_blocks_by_template_id/{id:[0-9a-f]+}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
if mainId, err := types.HashFromString(mux.Vars(request)["id"]); err == nil {
|
||||
if blocks := archiveCache.LoadByTemplateId(mainId); len(blocks) > 0 {
|
||||
|
||||
for _, b := range blocks {
|
||||
addPoolBlockMetadata(writer, b)
|
||||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = EncodeJson(request, writer, blocks)
|
||||
|
@ -900,8 +876,6 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
}
|
||||
|
||||
if b != nil {
|
||||
addPoolBlockMetadata(writer, b)
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
_ = EncodeJson(request, writer, b)
|
||||
|
@ -951,8 +925,7 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
result.Error = err.Error()
|
||||
} else {
|
||||
result.Blob = blob
|
||||
|
||||
addPoolBlockMetadata(writer, b)
|
||||
result.Metadata = b.Metadata
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -981,10 +954,10 @@ func getServerMux(instance *P2Pool) *mux.Router {
|
|||
})
|
||||
} else {
|
||||
result = append(result, P2PoolBinaryBlockResult{
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Version: int(b.ShareVersion()),
|
||||
Blob: blob,
|
||||
Metadata: b.Metadata,
|
||||
})
|
||||
addPoolBlockMetadata(writer, b)
|
||||
}
|
||||
}
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module git.gammaspectra.live/P2Pool/go-p2pool/v3
|
|||
go 1.22
|
||||
|
||||
require (
|
||||
git.gammaspectra.live/P2Pool/consensus/v3 v3.6.3
|
||||
git.gammaspectra.live/P2Pool/consensus/v3 v3.6.4
|
||||
git.gammaspectra.live/P2Pool/observer-cache-archive v0.0.0-20240413050335-08f79500c0c1
|
||||
github.com/gorilla/mux v1.8.1
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
|||
git.gammaspectra.live/P2Pool/consensus/v3 v3.6.3 h1:bDCJzl5Rm2VfSrRY7gLVzK43Y8JxznTTgZvpHcFmDnE=
|
||||
git.gammaspectra.live/P2Pool/consensus/v3 v3.6.3/go.mod h1:3mjTaEx2Hm9VUs0rZIjCAFV6fToNxnVDj616NEc9Y0I=
|
||||
git.gammaspectra.live/P2Pool/consensus/v3 v3.6.4 h1:z/+WQrPQK5RDdWwm2od9Ltpk9TFAyNhR7j1cTAFfe8Y=
|
||||
git.gammaspectra.live/P2Pool/consensus/v3 v3.6.4/go.mod h1:3mjTaEx2Hm9VUs0rZIjCAFV6fToNxnVDj616NEc9Y0I=
|
||||
git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00 h1:mDQY337iKB+kle5RYWL5CoAz+3DmnkAh/B2XD8B+PFk=
|
||||
git.gammaspectra.live/P2Pool/edwards25519 v0.0.0-20240405085108-e2f706cb5c00/go.mod h1:FZsrMWGucMP3SZamzrd7m562geIs5zp1O/9MGoiAKH0=
|
||||
git.gammaspectra.live/P2Pool/go-randomx/v2 v2.1.0 h1:L1fV2XBYFmpFU+JKP/7fsgDm2Lfh9yFlS+800v+3OsM=
|
||||
|
|
8
types.go
8
types.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.gammaspectra.live/P2Pool/consensus/v3/p2pool/sidechain"
|
||||
"git.gammaspectra.live/P2Pool/consensus/v3/types"
|
||||
)
|
||||
|
||||
|
@ -12,9 +13,10 @@ type P2PoolSideChainStateResult struct {
|
|||
}
|
||||
|
||||
type P2PoolBinaryBlockResult struct {
|
||||
Version int `json:"version"`
|
||||
Blob types.Bytes `json:"blob"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Version int `json:"version"`
|
||||
Blob types.Bytes `json:"blob"`
|
||||
Metadata sidechain.PoolBlockReceptionMetadata `json:"metadata,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type P2PoolSpecialBinaryBlockResult struct {
|
||||
|
|
Loading…
Reference in a new issue