Commit 2473c258 authored by David Vorick's avatar David Vorick

early validate transaction code

parent d816b840
whitepaper.aux
whitepaper.log
whitepaper.pdf
.*
......@@ -18,7 +18,8 @@ type State struct {
BadBlocks map[BlockID]struct{} // A list of blocks that don't verify.
BlockMap map[BlockID]BlockNode // A list of all blocks in the blocktree.
OrphanBlocks map[BlockID]Block // A list of all blocks that are orphans.
// FutureBlocks map[BlockID]Block // A list of blocks with out-of-range timestamps.
// OrphanBlocks map[BlockID]Block // A list of all blocks that are orphans.
OpenTransactions map[TransactionID]Transaction // Transactions that are not yet incorporated into the ConsensusState.
DeadTransactions map[TransactionID]Transaction // Transactions that spend outputs already in a block or open transaction.
......
......@@ -100,8 +100,3 @@ type StorageProof struct {
Segment [SegmentSize]byte
HashSet []*Hash
}
func (b Block) ID() (id BlockID) {
// Return the hash of the block.
return
}
......@@ -10,8 +10,11 @@ func BlockVerify(b Block) {
}
// Add a block to the state struct.
//
// Currently txns are not harvested from bad blocks. Good txns should be
// harvested from bad blocks.
func (s *State) IncorporateBlock(b Block) (err error) {
bid := b.ID()
bid := b.ID() // Function is not implemented.
_, exists := s.BadBlocks[bid]
if exists {
......@@ -25,8 +28,7 @@ func (s *State) IncorporateBlock(b Block) (err error) {
return
}
// If timestamp is in the future, return an error and store in future blocks list?
// Certainly it doesn't belong in bad blocks, but...
// If timestamp is in the future, store in future blocks list.
_, exists = s.BlockMap[bid]
if exists {
......@@ -34,18 +36,83 @@ func (s *State) IncorporateBlock(b Block) (err error) {
return
}
_, exists = s.OrphanBlocks[bid]
/*_, exists = s.OrphanBlocks[bid]
if exists {
err = errors.New("Block exists in orphan list")
return
}
} */
prevNode, exists := s.BlockMap[b.Prevblock]
if !exists {
OrphanBlocks[bid] = b
err = errors.New("Block is a new orphan")
// OrphanBlocks[bid] = b
err = errors.New("Block is an orphan")
return
}
// Check the amount of work done by the block.
// Check the hash on the merkle tree of transactions.
for _, txn := range b.Transactions {
// Validate each transaction.
err := s.ValidateTxn(txn)
if err != nil {
s.BadBlocks[bid] = struct{}{}
return
}
}
}
// If you are validating the block, then the consensus state needs to be
// pointing at the current branch in the fork tree.
func (s *State) ValidateBlock(b Block) (err error) {
// Move stuff from incorporate to here conditionally.
}
func (s *State) ValidateTxn(t Transaction) (err error) {
if t.Version != 1 {
err = errors.New("Transaction version is not recognized.")
return
}
// Check that the root is good.
inputSum := 0
outputSum := t.MinerFee
for _, input := range Inputs {
utxo, exists := s.ConsensusState[input.OutputID]
if !exists {
err = errors.New("Transaction spends a nonexisting output")
return
}
inputSum += utxo.Value
// Check that the spend conditions match the hash listed in the output.
// Check the timelock on the spend conditions is expired.
// Add the signature situation to some struct =/
}
for _, output := range t.Outputs {
outputSum += output.Value
}
for _, contract := range t.FileContracts {
outputSum := contract.ContractFund
// Check that start is in the future.
// Check that end is after start.
}
for _, proof := range t.StorageProofs {
// Check that the proof passes.
}
for _, sig := range t.Signatures {
// Check that each signature adds value to the input. (signs a unique public key, isn't frivilous)
// Check the timelock on the signature.
// Check that the actual signature is valid, following the covered fields struct.
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment