From 743983c82b601e200fa53d4aa8973f83ff628d29 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Wed, 12 Sep 2018 11:47:27 +0800 Subject: core: types: use []byte for block Payload type (#101) Change payload type to []byte instead of [][]byte to make it more generic. The user of the consensus core should marshal the payload into a byte slice by themselves. --- core/consensus.go | 4 ++-- core/crypto.go | 2 +- core/interfaces.go | 2 +- core/nonblocking-application.go | 8 ++++---- core/nonblocking-application_test.go | 4 ++-- core/test/app.go | 6 +++--- core/types/block.go | 9 +++------ simulation/app.go | 6 +++--- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/core/consensus.go b/core/consensus.go index 91ca657..0bc7c7d 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -517,7 +517,7 @@ func (con *Consensus) PrepareBlock(b *types.Block, con.rbModule.prepareBlock(b) b.Timestamp = proposeTime - b.Payloads = con.app.PreparePayloads(b.Position) + b.Payload = con.app.PreparePayload(b.Position) b.Hash, err = hashBlock(b) if err != nil { return @@ -535,7 +535,7 @@ func (con *Consensus) PrepareGenesisBlock(b *types.Block, if err = con.checkPrepareBlock(b, proposeTime); err != nil { return } - if len(b.Payloads) != 0 { + if len(b.Payload) != 0 { err = ErrGenesisBlockNotEmpty return } diff --git a/core/crypto.go b/core/crypto.go index 656dd74..3fe39ac 100644 --- a/core/crypto.go +++ b/core/crypto.go @@ -66,7 +66,7 @@ func hashBlock(block *types.Block) (common.Hash, error) { if err != nil { return common.Hash{}, err } - payloadHash := crypto.Keccak256Hash(block.Payloads...) + payloadHash := crypto.Keccak256Hash(block.Payload) hash := crypto.Keccak256Hash( block.ProposerID.Hash[:], diff --git a/core/interfaces.go b/core/interfaces.go index 080db20..c8f57e9 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -30,7 +30,7 @@ import ( // consensus core. type Application interface { // PreparePayload is called when consensus core is preparing a block. - PreparePayloads(position types.Position) [][]byte + PreparePayload(position types.Position) []byte // VerifyPayloads verifies if the payloads are valid. VerifyPayloads(payloads [][]byte) bool diff --git a/core/nonblocking-application.go b/core/nonblocking-application.go index 1e20fa4..7af12d4 100644 --- a/core/nonblocking-application.go +++ b/core/nonblocking-application.go @@ -120,10 +120,10 @@ func (app *nonBlockingApplication) wait() { app.running.Wait() } -// PreparePayloads cannot be non-blocking. -func (app *nonBlockingApplication) PreparePayloads( - position types.Position) [][]byte { - return app.app.PreparePayloads(position) +// PreparePayload cannot be non-blocking. +func (app *nonBlockingApplication) PreparePayload( + position types.Position) []byte { + return app.app.PreparePayload(position) } // VerifyPayloads cannot be non-blocking. diff --git a/core/nonblocking-application_test.go b/core/nonblocking-application_test.go index 1968445..a1dd727 100644 --- a/core/nonblocking-application_test.go +++ b/core/nonblocking-application_test.go @@ -47,8 +47,8 @@ func newSlowApp(sleep time.Duration) *slowApp { } } -func (app *slowApp) PreparePayloads(_ types.Position) [][]byte { - return [][]byte{} +func (app *slowApp) PreparePayload(_ types.Position) []byte { + return []byte{} } func (app *slowApp) VerifyPayloads(_ [][]byte) bool { diff --git a/core/test/app.go b/core/test/app.go index 60b74ac..76f1a10 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -102,9 +102,9 @@ func NewApp() *App { } } -// PreparePayloads implements Application interface. -func (app *App) PreparePayloads(position types.Position) [][]byte { - return [][]byte{} +// PreparePayload implements Application interface. +func (app *App) PreparePayload(position types.Position) []byte { + return []byte{} } // VerifyPayloads implements Application. diff --git a/core/types/block.go b/core/types/block.go index 3585a97..06712b1 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -63,7 +63,7 @@ type Block struct { Position Position `json:"position"` Timestamp time.Time `json:"timestamps"` Acks map[common.Hash]struct{} `json:"acks"` - Payloads [][]byte `json:"payloads"` + Payload []byte `json:"payload"` Signature crypto.Signature `json:"signature"` CRSSignature crypto.Signature `json:"crs_signature"` @@ -96,11 +96,8 @@ func (b *Block) Clone() (bcopy *Block) { for k, v := range b.Acks { bcopy.Acks[k] = v } - bcopy.Payloads = make([][]byte, len(b.Payloads)) - for k, v := range b.Payloads { - bcopy.Payloads[k] = make([]byte, len(v)) - copy(bcopy.Payloads[k], v) - } + bcopy.Payload = make([]byte, len(b.Payload)) + copy(bcopy.Payload, b.Payload) return } diff --git a/simulation/app.go b/simulation/app.go index c312204..40aa32b 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -94,9 +94,9 @@ func (a *simApp) getAckedBlocks(ackHash common.Hash) (output common.Hashes) { return } -// PreparePayloads implements core.Application. -func (a *simApp) PreparePayloads(position types.Position) [][]byte { - return [][]byte{} +// PreparePayload implements core.Application. +func (a *simApp) PreparePayload(position types.Position) []byte { + return []byte{} } // StronglyAcked is called when a block is strongly acked by DEXON -- cgit FreeBSD Ports (https://github.com/freebsd/freebsd-ports)
aboutsummaryrefslogtreecommitdiffstats
path: root/dns/acme-dns
Commit message (Expand)AuthorAgeFilesLines
* all: Bump PORTREVISION after lang/go{118,119} updateDmitri Goutnik2022-10-071-1/+1
* all: Bump PORTREVISION after lang/go{118,119} updateDmitri Goutnik2022-09-091-0/+1
* Remove WWW entries moved into port MakefilesStefan Eßer2022-09-081-2/+0
* Add WWW entries to port MakefilesStefan Eßer2022-09-081-0/+1
* dns/acme-dns: Bump PORTEPOCHFernando Apesteguía2022-08-141-0/+1
* dns/acme-dns: update to 1.0punkt.de Hosting Team2022-08-142-68/+66
* all: Bump PORTREVISION after Go updateDmitri Goutnik2022-08-041-1/+1
* all: Bump PORTREVISION after lang/go{117,118} updateDmitri Goutnik2022-07-141-1/+1
* */*: Bump port revisons after lang/go{117,118} updateDmitri Goutnik2022-06-081-0/+1
* dns/acme-dns: Revert update to 0.8Koichiro Iwao2022-05-252-86/+108
* dns/acme-dns: Update to 0.8punkt.de Hosting Team2022-05-252-107/+86