aboutsummaryrefslogtreecommitdiffstats
path: root/core/block_validator.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-11-15 13:30:50 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commitdbb3d8fd30bd33df37f13048dc334ead8d335ddc (patch)
tree7f22be12a919cacdc79912444b34d20523448582 /core/block_validator.go
parent281bf328e19274e21416ecbbc5c01f6243c1ad6f (diff)
downloadgo-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.tar
go-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.tar.gz
go-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.tar.bz2
go-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.tar.lz
go-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.tar.xz
go-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.tar.zst
go-tangerine-dbb3d8fd30bd33df37f13048dc334ead8d335ddc.zip
core: refactor validator and fix light node sync (#25)
Remove custom Dexon validator by adding a new `ValidateWitnessData` method into the validator interface. This allow us to properly detect know blocks. This also allow other gdex "light" client to sync compaction chain. Also, setup a standalone RPC node for handling RPC reqeusts.
Diffstat (limited to 'core/block_validator.go')
-rw-r--r--core/block_validator.go41
1 files changed, 12 insertions, 29 deletions
diff --git a/core/block_validator.go b/core/block_validator.go
index 65f311f9f..09539790b 100644
--- a/core/block_validator.go
+++ b/core/block_validator.go
@@ -101,37 +101,20 @@ func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *stat
return nil
}
-// BlockValidator implements Validator.
-type DexonBlockValidator struct {
- config *params.ChainConfig // Chain configuration options
- bc *BlockChain // Canonical block chain
- engine consensus.Engine // Consensus engine used for validating
-}
+func (v *BlockValidator) ValidateWitnessData(height uint64, data types.WitnessData) error {
+ currentBlock := v.bc.CurrentBlock()
+ if height > currentBlock.NumberU64() && height != 0 {
+ pendingBlock := v.bc.GetPendingBlockByNumber(height)
-// NewDexonBlockValidator returns a new block validator which is safe for re-use
-func NewDexonBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *DexonBlockValidator {
- validator := &DexonBlockValidator{
- config: config,
- engine: engine,
- bc: blockchain,
+ if pendingBlock.Root() != data.Root {
+ return fmt.Errorf("invalid witness root %s vs %s",
+ pendingBlock.Root().String(), data.Root.String())
+ }
+ if pendingBlock.ReceiptHash() != data.ReceiptHash {
+ return fmt.Errorf("invalid witness receipt hash %s vs %s",
+ pendingBlock.ReceiptHash().String(), data.ReceiptHash.String())
+ }
}
- return validator
-}
-
-// ValidateBody validates the given block's uncles and verifies the block
-// header's transaction and uncle roots. The headers are assumed to be already
-// validated at this point.
-func (v *DexonBlockValidator) ValidateBody(block *types.Block) error {
- // TODO(Bojie): implement it
- return nil
-}
-
-// ValidateState validates the various changes that happen after a state
-// transition, such as amount of used gas, the receipt roots and the state root
-// itself. ValidateState returns a database batch if the validation was a success
-// otherwise nil and an error is returned.
-func (v *DexonBlockValidator) ValidateState(block, parent *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error {
- // TODO(Bojie): implement it
return nil
}