diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/interfaces.go | 8 | ||||
-rw-r--r-- | core/lattice.go | 8 | ||||
-rw-r--r-- | core/nodeset-cache_test.go | 5 | ||||
-rw-r--r-- | core/nonblocking.go | 4 | ||||
-rw-r--r-- | core/nonblocking_test.go | 8 | ||||
-rw-r--r-- | core/test/app.go | 8 | ||||
-rw-r--r-- | core/test/governance.go | 4 |
7 files changed, 29 insertions, 16 deletions
diff --git a/core/interfaces.go b/core/interfaces.go index 7a5859e..4a20354 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -29,10 +29,10 @@ import ( // consensus core. type Application interface { // PreparePayload is called when consensus core is preparing a block. - PreparePayload(position types.Position) []byte + PreparePayload(position types.Position) ([]byte, error) // PrepareWitness will return the witness data no lower than consensusHeight. - PrepareWitness(consensusHeight uint64) types.Witness + PrepareWitness(consensusHeight uint64) (types.Witness, error) // VerifyBlock verifies if the block is valid. VerifyBlock(block *types.Block) bool @@ -103,6 +103,10 @@ type Governance interface { // Return the genesis node set if round == 0. NodeSet(round uint64) []crypto.PublicKey + // NotifyRoundHeight notifies governance contract to generate configuration + // for that round with the block on that consensus height. + NotifyRoundHeight(targetRound, consensusHeight uint64) + //// DKG-related methods. // AddDKGComplaint adds a DKGComplaint. diff --git a/core/lattice.go b/core/lattice.go index d634650..ab8aaec 100644 --- a/core/lattice.go +++ b/core/lattice.go @@ -79,8 +79,12 @@ func (s *Lattice) PrepareBlock( if err = s.data.prepareBlock(b); err != nil { return } - b.Payload = s.app.PreparePayload(b.Position) - b.Witness = s.app.PrepareWitness(b.Witness.Height) + if b.Payload, err = s.app.PreparePayload(b.Position); err != nil { + return + } + if b.Witness, err = s.app.PrepareWitness(b.Witness.Height); err != nil { + return + } if err = s.authModule.SignBlock(b); err != nil { return } diff --git a/core/nodeset-cache_test.go b/core/nodeset-cache_test.go index 6324421..73f0dee 100644 --- a/core/nodeset-cache_test.go +++ b/core/nodeset-cache_test.go @@ -40,8 +40,9 @@ func (g *testGov) Configuration(round uint64) (cfg *types.Config) { NumChains: 4, } } -func (g *testGov) CRS(round uint64) (b common.Hash) { return g.crs } -func (g *testGov) ProposeCRS([]byte) {} +func (g *testGov) CRS(round uint64) (b common.Hash) { return g.crs } +func (g *testGov) ProposeCRS([]byte) {} +func (g *testGov) NotifyRoundHeight(round, height uint64) {} func (g *testGov) NodeSet(round uint64) []crypto.PublicKey { // Randomly generating keys, and check them for verification. g.curKeys = []crypto.PublicKey{} diff --git a/core/nonblocking.go b/core/nonblocking.go index 9bedb4b..532bcb9 100644 --- a/core/nonblocking.go +++ b/core/nonblocking.go @@ -119,12 +119,12 @@ func (nb *nonBlocking) wait() { } // PreparePayload cannot be non-blocking. -func (nb *nonBlocking) PreparePayload(position types.Position) []byte { +func (nb *nonBlocking) PreparePayload(position types.Position) ([]byte, error) { return nb.app.PreparePayload(position) } // PrepareWitness cannot be non-blocking. -func (nb *nonBlocking) PrepareWitness(height uint64) types.Witness { +func (nb *nonBlocking) PrepareWitness(height uint64) (types.Witness, error) { return nb.app.PrepareWitness(height) } diff --git a/core/nonblocking_test.go b/core/nonblocking_test.go index 8cd42d0..50f580a 100644 --- a/core/nonblocking_test.go +++ b/core/nonblocking_test.go @@ -45,12 +45,12 @@ func newSlowApp(sleep time.Duration) *slowApp { } } -func (app *slowApp) PreparePayload(_ types.Position) []byte { - return []byte{} +func (app *slowApp) PreparePayload(_ types.Position) ([]byte, error) { + return []byte{}, nil } -func (app *slowApp) PrepareWitness(_ uint64) types.Witness { - return types.Witness{} +func (app *slowApp) PrepareWitness(_ uint64) (types.Witness, error) { + return types.Witness{}, nil } func (app *slowApp) VerifyBlock(_ *types.Block) bool { diff --git a/core/test/app.go b/core/test/app.go index 60bc26f..d9582c9 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -97,15 +97,15 @@ func NewApp() *App { } // PreparePayload implements Application interface. -func (app *App) PreparePayload(position types.Position) []byte { - return []byte{} +func (app *App) PreparePayload(position types.Position) ([]byte, error) { + return []byte{}, nil } // PrepareWitness implements Application interface. -func (app *App) PrepareWitness(height uint64) types.Witness { +func (app *App) PrepareWitness(height uint64) (types.Witness, error) { return types.Witness{ Height: height, - } + }, nil } // VerifyBlock implements Application. diff --git a/core/test/governance.go b/core/test/governance.go index de0ec21..88aab37 100644 --- a/core/test/governance.go +++ b/core/test/governance.go @@ -115,6 +115,10 @@ func (g *Governance) CRS(round uint64) common.Hash { return g.crs[round] } +// NotifyRoundHeight notifies governace contract to snapshot config. +func (g *Governance) NotifyRoundHeight(round, height uint64) { +} + // ProposeCRS propose a CRS. func (g *Governance) ProposeCRS(signedCRS []byte) { g.lock.Lock() |